diff options
Diffstat (limited to 'include/llvm/ADT/StringRef.h')
-rw-r--r-- | include/llvm/ADT/StringRef.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 76ba66e746..b54856842c 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -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); + } + /// @} }; |