[llvm-commits] PATCH: Additional SmallString methods
Jim Grosbach
grosbach at apple.com
Fri Jan 20 12:17:54 PST 2012
Hi Talin,
There's already a conversion operator to StringRef. Does that not handle things for you?
// Implicit conversion to StringRef.
operator StringRef() const { return str(); }
-j
On Jan 19, 2012, at 11:42 PM, Talin wrote:
> This patch adds many convenience methods to class SmallString:
> void assign(unsigned NumElts, char Elt);
> void assign(in_iter S, in_iter E);
> void assign(StringRef RHS);
> void assign(const SmallVectorImpl<char> &RHS);
> void append(in_iter S, in_iter E);
> void append(StringRef RHS);
> void append(const SmallVectorImpl<char> &RHS);
> bool equals(StringRef RHS) const;
> bool equals_lower(StringRef RHS) const;
> int compare(StringRef RHS) const;
> int compare_lower(StringRef RHS) const;
> int compare_numeric(StringRef RHS) const;
> bool startswith(StringRef Prefix) const;
> bool endswith(StringRef Suffix) const;
> size_t find(char C, size_t From = 0) const;
> size_t find(StringRef Str, size_t From = 0) const;
> size_t rfind(char C, size_t From = StringRef::npos) const;
> size_t rfind(StringRef Str) const;
> size_t find_first_of(char C, size_t From = 0) const;
> size_t find_first_of(StringRef Chars, size_t From = 0) const;
> size_t find_first_not_of(char C, size_t From = 0) const;
> size_t find_first_not_of(StringRef Chars, size_t From = 0) const;
> size_t find_last_of(char C, size_t From = StringRef::npos) const;
> size_t find_last_of(StringRef Chars, size_t From = StringRef::npos) const;
> size_t count(char C) const;
> size_t count(StringRef Str) const;
> StringRef substr(size_t Start, size_t N = StringRef::npos) const;
> StringRef slice(size_t Start, size_t End) const;
> Most of the methods are taken directly from StringRef (find_x, compare_x, substr, and so on). My motivation for adding these methods is that often I find myself working with a SmallString instead of a StringRef, and it would be nice to call substr() for example directly without having to convert to a StringRef. Internally, of course, the methods simply convert the SmallString to a StringRef (which is extremely cheap), and then call the corresponding StringRef method. Doing it this way minimizes template expansion, since StringRef is a non-template class.
>
> The 'assign' and 'append' methods are taken from standard STL, with additional overloads that are convenient for strings. For example, assign() now allows assigning to a SmallString from an iterator pair, which was not supported before.
>
> (Note: I thought about adding support for assign/append/construct from an ArrayRef<char>, but that would add an additional include file dependency.)
>
> This patch also includes many additions to the unit tests for SmallString, as well as some minor typographical cleanups in the comments in SmallString.h.
>
> --
> -- Talin
> <smallstring.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120120/89c04050/attachment.html>
More information about the llvm-commits
mailing list