----------------------------------------------------------------------------- Finds a string in another string with a case insensitive test -----------------------------------------------------------------------------
| 157 | // Finds a string in another string with a case insensitive test |
| 158 | //----------------------------------------------------------------------------- |
| 159 | char const* V_stristr( char const* pStr, char const* pSearch ) |
| 160 | { |
| 161 | Assert( pStr != NULL ); |
| 162 | Assert( pSearch != NULL ); |
| 163 | |
| 164 | if ( pStr == NULL || pSearch == NULL ) |
| 165 | return NULL; |
| 166 | |
| 167 | char const* pLetter = pStr; |
| 168 | |
| 169 | // Check the entire string |
| 170 | while ( *pLetter != 0 ) |
| 171 | { |
| 172 | // Skip over non-matches |
| 173 | if ( tolower( (unsigned char) *pLetter ) == tolower( (unsigned char) *pSearch ) ) |
| 174 | { |
| 175 | // Check for match |
| 176 | char const* pMatch = pLetter + 1; |
| 177 | char const* pTest = pSearch + 1; |
| 178 | while (*pTest != 0) |
| 179 | { |
| 180 | // We've run off the end; don't bother. |
| 181 | if (*pMatch == 0) |
| 182 | return 0; |
| 183 | |
| 184 | if ( tolower( (unsigned char) *pMatch ) != tolower( (unsigned char) *pTest ) ) |
| 185 | break; |
| 186 | |
| 187 | ++pMatch; |
| 188 | ++pTest; |
| 189 | } |
| 190 | |
| 191 | // Found a match! |
| 192 | if ( *pTest == 0 ) |
| 193 | return pLetter; |
| 194 | } |
| 195 | |
| 196 | ++pLetter; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | //----------------------------------------------------------------------------- |
| 203 | // Purpose: Convert ASCII characters to lower case in-place |
no outgoing calls
no test coverage detected