summaryrefslogtreecommitdiff
path: root/lib/Support/StringRef.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-05-11 22:08:50 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-05-11 22:08:50 +0000
commitb0940b46edbbe9d3f62d7f6f70330fd87f3507e1 (patch)
tree3b2c5e9cf13c8ae42336d7a065564d31da172508 /lib/Support/StringRef.cpp
parent9df5ec3984c6197939e5a9b1d3b893e909ca0632 (diff)
downloadllvm-b0940b46edbbe9d3f62d7f6f70330fd87f3507e1.tar.gz
llvm-b0940b46edbbe9d3f62d7f6f70330fd87f3507e1.tar.bz2
llvm-b0940b46edbbe9d3f62d7f6f70330fd87f3507e1.tar.xz
[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
Diffstat (limited to 'lib/Support/StringRef.cpp')
-rw-r--r--lib/Support/StringRef.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp
index 97af0fff5e..8aab4b2760 100644
--- a/lib/Support/StringRef.cpp
+++ b/lib/Support/StringRef.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/edit_distance.h"
+
#include <bitset>
using namespace llvm;
@@ -230,6 +231,31 @@ StringRef::size_type StringRef::find_last_of(StringRef Chars,
return npos;
}
+/// find_last_not_of - Find the last character in the string that is not
+/// \arg C, or npos if not found.
+StringRef::size_type StringRef::find_last_not_of(char C, size_t From) const {
+ for (size_type i = min(From, Length) - 1, e = -1; i != e; --i)
+ if (Data[i] != C)
+ return i;
+ return npos;
+}
+
+/// 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())
+StringRef::size_type StringRef::find_last_not_of(StringRef Chars,
+ size_t From) const {
+ std::bitset<1 << CHAR_BIT> CharBits;
+ for (size_type i = 0, e = Chars.size(); i != e; ++i)
+ CharBits.set((unsigned char)Chars[i]);
+
+ for (size_type i = min(From, Length) - 1, e = -1; i != e; --i)
+ if (!CharBits.test((unsigned char)Data[i]))
+ return i;
+ return npos;
+}
+
void StringRef::split(SmallVectorImpl<StringRef> &A,
StringRef Separators, int MaxSplit,
bool KeepEmpty) const {