[llvm-commits] [llvm] r82347 - in /llvm/trunk: include/llvm/ADT/StringRef.h lib/Support/StringRef.cpp
Chris Lattner
sabre at nondot.org
Sat Sep 19 18:22:16 PDT 2009
Author: lattner
Date: Sat Sep 19 20:22:16 2009
New Revision: 82347
URL: http://llvm.org/viewvc/llvm-project?rev=82347&view=rev
Log:
move a couple non-trivial methods out of line, add new
find_first_of/find_first_of methods.
Modified:
llvm/trunk/include/llvm/ADT/StringRef.h
llvm/trunk/lib/Support/StringRef.cpp
Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=82347&r1=82346&r2=82347&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Sat Sep 19 20:22:16 2009
@@ -163,16 +163,8 @@
///
/// \return - The index of the first occurence of \arg Str, or npos if not
/// found.
- size_t find(const StringRef &Str) const {
- size_t N = Str.size();
- if (N > Length)
- return npos;
- for (size_t i = 0, e = Length - N + 1; i != e; ++i)
- if (substr(i, N).equals(Str))
- return i;
- return npos;
- }
-
+ size_t find(const StringRef &Str) const;
+
/// rfind - Search for the last character \arg C in the string.
///
/// \return - The index of the last occurence of \arg C, or npos if not
@@ -189,24 +181,29 @@
size_t rfind(char C) const {
return rfind(C, Length);
}
-
-
+
/// rfind - Search for the last string \arg Str in the string.
///
/// \return - The index of the last occurence of \arg Str, or npos if not
/// found.
- size_t rfind(const StringRef &Str) const {
- size_t N = Str.size();
- if (N > Length)
- return npos;
- for (size_t i = Length - N + 1, e = 0; i != e;) {
- --i;
- if (substr(i, N).equals(Str))
- return i;
- }
- return npos;
- }
-
+ size_t rfind(const StringRef &Str) const;
+
+ /// find_first_of - Find the first instance of the specified character or
+ /// return npos if not in string. Same as find.
+ size_type find_first_of(char C) const { return find(C); }
+
+ /// find_first_of - Find the first character from the string 'Chars' in the
+ /// current string or return npos if not in string.
+ size_type find_first_of(StringRef Chars) const;
+
+ /// find_first_not_of - Find the first character in the string that is not
+ /// in the string 'Chars' or return npos if all are in string. Same as find.
+ size_type find_first_not_of(StringRef Chars) const;
+
+ /// @}
+ /// @name Helpful Algorithms
+ /// @{
+
/// count - Return the number of occurrences of \arg C in the string.
size_t count(char C) const {
size_t Count = 0;
@@ -215,23 +212,10 @@
++Count;
return Count;
}
-
+
/// count - Return the number of non-overlapped occurrences of \arg Str in
/// the string.
- size_t count(const StringRef &Str) const {
- size_t Count = 0;
- size_t N = Str.size();
- if (N > Length)
- return 0;
- for (size_t i = 0, e = Length - N + 1; i != e; ++i)
- if (substr(i, N).equals(Str))
- ++Count;
- return Count;
- }
-
- /// @}
- /// @name Helpful Algorithms
- /// @{
+ size_t count(const StringRef &Str) const;
/// getAsInteger - Parse the current string as an integer of the specified
/// radix. If Radix is specified as zero, this does radix autosensing using
Modified: llvm/trunk/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=82347&r1=82346&r2=82347&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Sat Sep 19 20:22:16 2009
@@ -12,6 +12,77 @@
const size_t StringRef::npos;
+//===----------------------------------------------------------------------===//
+// String Searching
+//===----------------------------------------------------------------------===//
+
+
+/// find - Search for the first string \arg Str in the string.
+///
+/// \return - The index of the first occurence of \arg Str, or npos if not
+/// found.
+size_t StringRef::find(const StringRef &Str) const {
+ size_t N = Str.size();
+ if (N > Length)
+ return npos;
+ for (size_t i = 0, e = Length - N + 1; i != e; ++i)
+ if (substr(i, N).equals(Str))
+ return i;
+ return npos;
+}
+
+/// rfind - Search for the last string \arg Str in the string.
+///
+/// \return - The index of the last occurence of \arg Str, or npos if not
+/// found.
+size_t StringRef::rfind(const StringRef &Str) const {
+ size_t N = Str.size();
+ if (N > Length)
+ return npos;
+ for (size_t i = Length - N + 1, e = 0; i != e;) {
+ --i;
+ if (substr(i, N).equals(Str))
+ return i;
+ }
+ return npos;
+}
+
+/// find_first_of - Find the first character from the string 'Chars' in the
+/// current string or return npos if not in string.
+StringRef::size_type StringRef::find_first_of(StringRef Chars) const {
+ for (size_type i = 0, e = Length; i != e; ++i)
+ if (Chars.find(Data[i]) != npos)
+ return i;
+ return npos;
+}
+
+/// find_first_not_of - Find the first character in the string that is not
+/// in the string 'Chars' or return npos if all are in string. Same as find.
+StringRef::size_type StringRef::find_first_not_of(StringRef Chars) const {
+ for (size_type i = 0, e = Length; i != e; ++i)
+ if (Chars.find(Data[i]) == npos)
+ return i;
+ return npos;
+}
+
+
+//===----------------------------------------------------------------------===//
+// Helpful Algorithms
+//===----------------------------------------------------------------------===//
+
+/// count - Return the number of non-overlapped occurrences of \arg Str in
+/// the string.
+size_t StringRef::count(const StringRef &Str) const {
+ size_t Count = 0;
+ size_t N = Str.size();
+ if (N > Length)
+ return 0;
+ for (size_t i = 0, e = Length - N + 1; i != e; ++i)
+ if (substr(i, N).equals(Str))
+ ++Count;
+ return Count;
+}
+
/// GetAsUnsignedInteger - Workhorse method that converts a integer character
/// sequence of radix up to 36 to an unsigned long long value.
static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix,
More information about the llvm-commits
mailing list