diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-11-30 23:27:35 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-11-30 23:27:35 +0000 |
commit | e1d3603dc6d4d6fc563e9197fb83da861cf0ef97 (patch) | |
tree | dae5c05195887f65cd0eccf11715326a0d700bac /llvm/lib/Support/StringRef.cpp | |
parent | c440e7912652835bbd73103025b313e07cdc5c24 (diff) | |
download | bcm5719-llvm-e1d3603dc6d4d6fc563e9197fb83da861cf0ef97.tar.gz bcm5719-llvm-e1d3603dc6d4d6fc563e9197fb83da861cf0ef97.zip |
Support/ADT/StringRef: Add find_last_of.
llvm-svn: 120495
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | llvm/lib/Support/StringRef.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index 0e09122e766..8e636c3317f 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -200,6 +200,21 @@ StringRef::size_type StringRef::find_first_not_of(StringRef Chars, return npos; } +/// find_last_of - Find the last character in the string that is in \arg C, +/// or npos if not found. +/// +/// Note: O(size() + Chars.size()) +StringRef::size_type StringRef::find_last_of(StringRef Chars, + size_t From) const { + std::bitset<1 << CHAR_BIT> CharBits; + for (size_type i = 0; i != Chars.size(); ++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; +} //===----------------------------------------------------------------------===// // Helpful Algorithms |