llvm.org GIT mirror llvm / 6925f50
Added CStrInCStrNoCase, a portable implementation of strcasestr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50821 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 12 years ago
1 changed file(s) with 24 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
140140 }
141141 return RHS[LHS.size()] == 0; // Not too long?
142142 }
143
144 /// CStrInCStrNoCase - Portable version of strcasestr. Locates the first
145 /// occurance of c-string 's1' in string 's2', ignoring case. Returns
146 /// NULL if 's1' cannot be found.
147 static inline const char* CStrInCStrNoCase(const char *s1, const char *s2) {
148
149 // Are either strings NULL?
150 if (!s1 || !s2)
151 return 0;
152
153 const char *I1=s1, *I2=s2;
154
155 while (*I1 != '\0' || *I2 != '\0' )
156 if (tolower(*I1) != tolower(*I2)) { // No match. Start over.
157 ++s1; I1 = s1; I2 = s2;
158 }
159 else { // Character match. Advance to the next character.
160 ++I1; ++I2;
161 }
162
163 // If we exhausted all of the characters in 's2', then 's1' does not occur
164 // in it.
165 return *I2 == '\0' ? 0 : I1;
166 }
143167
144168 /// getToken - This function extracts one token from source, ignoring any
145169 /// leading characters that appear in the Delimiters string, and ending the