[llvm-commits] [llvm] r93174 - in /llvm/trunk: include/llvm/ADT/StringExtras.h lib/Support/StringExtras.cpp

Benjamin Kramer benny.kra at googlemail.com
Mon Jan 11 11:45:19 PST 2010


Author: d0k
Date: Mon Jan 11 13:45:18 2010
New Revision: 93174

URL: http://llvm.org/viewvc/llvm-project?rev=93174&view=rev
Log:
Add StrInStrNoCase, a StringRef version of CStrInCStrNoCase.

Modified:
    llvm/trunk/include/llvm/ADT/StringExtras.h
    llvm/trunk/lib/Support/StringExtras.cpp

Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=93174&r1=93173&r2=93174&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Mon Jan 11 13:45:18 2010
@@ -203,6 +203,11 @@
   return *I2 == '\0' ? s1 : 0;
 }
 
+/// StrInStrNoCase - Portable version of strcasestr.  Locates the first
+/// occurrence of string 's1' in string 's2', ignoring case.  Returns
+/// the offset of s2 in s1 or npos if s2 cannot be found.
+StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2);
+
 /// getToken - This function extracts one token from source, ignoring any
 /// leading characters that appear in the Delimiters string, and ending the
 /// token at any of the characters that appear in the Delimiters string.  If

Modified: llvm/trunk/lib/Support/StringExtras.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringExtras.cpp?rev=93174&r1=93173&r2=93174&view=diff

==============================================================================
--- llvm/trunk/lib/Support/StringExtras.cpp (original)
+++ llvm/trunk/lib/Support/StringExtras.cpp Mon Jan 11 13:45:18 2010
@@ -16,6 +16,19 @@
 #include "llvm/ADT/StringExtras.h"
 using namespace llvm;
 
+/// StrInStrNoCase - Portable version of strcasestr.  Locates the first
+/// occurrence of string 's1' in string 's2', ignoring case.  Returns
+/// the offset of s2 in s1 or npos if s2 cannot be found.
+StringRef::size_type llvm::StrInStrNoCase(StringRef s1, StringRef s2) {
+  size_t N = s2.size(), M = s1.size();
+  if (N > M)
+    return StringRef::npos;
+  for (size_t i = 0, e = M - N + 1; i != e; ++i)
+    if (s1.substr(i, N).equals_lower(s2))
+      return i;
+  return StringRef::npos;
+}
+
 /// getToken - This function extracts one token from source, ignoring any
 /// leading characters that appear in the Delimiters string, and ending the
 /// token at any of the characters that appear in the Delimiters string.  If





More information about the llvm-commits mailing list