This patch adds many convenience methods to class SmallString:<div><div><ul><li>void assign(unsigned NumElts, char Elt);</li><li>void assign(in_iter S, in_iter E);</li><li>void assign(StringRef RHS);</li><li>void assign(const SmallVectorImpl<char> &RHS);</li>
<li>void append(in_iter S, in_iter E);</li><li>void append(StringRef RHS);</li><li>void append(const SmallVectorImpl<char> &RHS);</li><li>bool equals(StringRef RHS) const;</li><li>bool equals_lower(StringRef RHS) const;</li>
<li>int compare(StringRef RHS) const;</li><li>int compare_lower(StringRef RHS) const;</li><li>int compare_numeric(StringRef RHS) const;</li><li>bool startswith(StringRef Prefix) const;</li><li>bool endswith(StringRef Suffix) const;</li>
<li>size_t find(char C, size_t From = 0) const;</li><li>size_t find(StringRef Str, size_t From = 0) const;</li><li>size_t rfind(char C, size_t From = StringRef::npos) const;</li><li>size_t rfind(StringRef Str) const;</li>
<li>size_t find_first_of(char C, size_t From = 0) const;</li><li>size_t find_first_of(StringRef Chars, size_t From = 0) const;</li><li>size_t find_first_not_of(char C, size_t From = 0) const;</li><li>size_t find_first_not_of(StringRef Chars, size_t From = 0) const;</li>
<li>size_t find_last_of(char C, size_t From = StringRef::npos) const;</li><li>size_t find_last_of(StringRef Chars, size_t From = StringRef::npos) const;</li><li>size_t count(char C) const;</li><li>size_t count(StringRef Str) const;</li>
<li>StringRef substr(size_t Start, size_t N = StringRef::npos) const;</li><li>StringRef slice(size_t Start, size_t End) const;</li></ul></div><div>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.</div>
<div><div><div><div><div><br></div><div>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.</div>
<div><br></div><div>(Note: I thought about adding support for assign/append/construct from an ArrayRef<char>, but that would add an additional include file dependency.)</div><div><br></div><div>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.</div>
<div><br></div>-- <br>-- Talin<br>
</div></div></div></div></div>