llvm.org GIT mirror llvm / 7462b5d
Add StrInStrNoCase, a StringRef version of CStrInCStrNoCase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93174 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 10 years ago
2 changed file(s) with 18 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
202202 return *I2 == '\0' ? s1 : 0;
203203 }
204204
205 /// StrInStrNoCase - Portable version of strcasestr. Locates the first
206 /// occurrence of string 's1' in string 's2', ignoring case. Returns
207 /// the offset of s2 in s1 or npos if s2 cannot be found.
208 StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2);
209
205210 /// getToken - This function extracts one token from source, ignoring any
206211 /// leading characters that appear in the Delimiters string, and ending the
207212 /// token at any of the characters that appear in the Delimiters string. If
1414 #include "llvm/ADT/STLExtras.h"
1515 #include "llvm/ADT/StringExtras.h"
1616 using namespace llvm;
17
18 /// StrInStrNoCase - Portable version of strcasestr. Locates the first
19 /// occurrence of string 's1' in string 's2', ignoring case. Returns
20 /// the offset of s2 in s1 or npos if s2 cannot be found.
21 StringRef::size_type llvm::StrInStrNoCase(StringRef s1, StringRef s2) {
22 size_t N = s2.size(), M = s1.size();
23 if (N > M)
24 return StringRef::npos;
25 for (size_t i = 0, e = M - N + 1; i != e; ++i)
26 if (s1.substr(i, N).equals_lower(s2))
27 return i;
28 return StringRef::npos;
29 }
1730
1831 /// getToken - This function extracts one token from source, ignoring any
1932 /// leading characters that appear in the Delimiters string, and ending the