[Support/StringRef] Add find_last_not_of and {r,l,}trim.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156652 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer
2012-05-11 22:08:50 +00:00
parent 9df5ec3984
commit b0940b46ed
3 changed files with 76 additions and 0 deletions

View File

@ -292,6 +292,16 @@ namespace llvm {
/// Note: O(size() + Chars.size())
size_type find_last_of(StringRef Chars, size_t From = npos) const;
/// find_last_not_of - Find the last character in the string that is not
/// \arg C, or npos if not found.
size_type find_last_not_of(char C, size_t From = npos) const;
/// find_last_not_of - Find the last character in the string that is not in
/// \arg Chars, or npos if not found.
///
/// Note: O(size() + Chars.size())
size_type find_last_not_of(StringRef Chars, size_t From = npos) const;
/// @}
/// @name Helpful Algorithms
/// @{
@ -480,6 +490,18 @@ namespace llvm {
return std::make_pair(slice(0, Idx), slice(Idx+1, npos));
}
StringRef ltrim(StringRef Chars = " \t\n\v\f\r") const {
return drop_front(std::min(Length, find_first_not_of(Chars)));
}
StringRef rtrim(StringRef Chars = " \t\n\v\f\r") const {
return drop_back(Length - std::min(Length, find_last_not_of(Chars) + 1));
}
StringRef trim(StringRef Chars = " \t\n\v\f\r") const {
return ltrim(Chars).rtrim(Chars);
}
/// @}
};