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 | 63c133b67d61b0c457ff46c957aed2b8d90b599c (patch) | |
tree | eb808ddacc2c57f6f9bbf5693e478c4221a40d90 /lib/Support | |
parent | 61db62990b4bae51c5434b1a494a7ee30fd2af26 (diff) | |
download | external_llvm-63c133b67d61b0c457ff46c957aed2b8d90b599c.zip external_llvm-63c133b67d61b0c457ff46c957aed2b8d90b599c.tar.gz external_llvm-63c133b67d61b0c457ff46c957aed2b8d90b599c.tar.bz2 |
Support/ADT/StringRef: Add find_last_of.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120495 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/StringRef.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp index 0e09122..8e636c3 100644 --- a/lib/Support/StringRef.cpp +++ b/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 |