tier1/strtools.cpp
const char* V_strnistr( const char* pStr, const char* pSearch, int n )
{
	Assert( pStr );
	Assert( pSearch );
	if (!pStr || !pSearch) 
		return 0;

	const char* pLetter = pStr;

	// Check the entire string
	while (*pLetter != 0)
	{
		if ( n <= 0 )
			return 0;

		// Skip over non-matches
		if (FastASCIIToLower(*pLetter) == FastASCIIToLower(*pSearch))
		{
			int n1 = n - 1;

			// Check for match
			const char* pMatch = pLetter + 1;
			const char* pTest = pSearch + 1;
			while (*pTest != 0)
			{
				if ( n1 <= 0 )
					return 0;

				// We've run off the end; don't bother.
				if (*pMatch == 0)
					return 0;

				if (FastASCIIToLower(*pMatch) != FastASCIIToLower(*pTest))
					break;

				++pMatch;
				++pTest;
				--n1;
			}

			// Found a match!
			if (*pTest == 0)
				return pLetter;
		}

		++pLetter;
		--n;
	}

	return 0;
}
//-----------------------------------------------------------------------------
// Finds a string in another string with a case insensitive test w/ length validation
//-----------------------------------------------------------------------------
Finds a string in another string with a case insensitive test w/ length validation
Finds a string in another string with a case insensitive test w / length validation
const char* V_strnistr( const char* pStr, const char* pSearch, int n )
{
	Assert( pStr );
	Assert( pSearch );
	if (!pStr || !pSearch) 
		return 0;
	const char* pLetter = pStr;
	while (*pLetter != 0)
	{
		if ( n <= 0 )
			return 0;
		if (FastASCIIToLower(*pLetter) == FastASCIIToLower(*pSearch))
		{
			int n1 = n - 1;
			const char* pMatch = pLetter + 1;
			const char* pTest = pSearch + 1;
			while (*pTest != 0)
			{
				if ( n1 <= 0 )
					return 0;
				if (*pMatch == 0)
					return 0;
				if (FastASCIIToLower(*pMatch) != FastASCIIToLower(*pTest))
					break;
				++pMatch;
				++pTest;
				--n1;
			}
			if (*pTest == 0)
				return pLetter;
		}
		++pLetter;
		--n;
	}
	return 0;
}
const char * V_strnistr ( const char * pStr , const char * pSearch , int n ) { Assert ( pStr ) ; Assert ( pSearch ) ; if ( ! pStr || ! pSearch ) return 0 ; const char * pLetter = pStr ; while ( * pLetter != 0 ) { if ( n <= 0 ) return 0 ; if ( FastASCIIToLower ( * pLetter ) == FastASCIIToLower ( * pSearch ) ) { int n1 = n - 1 ; const char * pMatch = pLetter + 1 ; const char * pTest = pSearch + 1 ; while ( * pTest != 0 ) { if ( n1 <= 0 ) return 0 ; if ( * pMatch == 0 ) return 0 ; if ( FastASCIIToLower ( * pMatch ) != FastASCIIToLower ( * pTest ) ) break ; ++ pMatch ; ++ pTest ; -- n1 ; } if ( * pTest == 0 ) return pLetter ; } ++ pLetter ; -- n ; } return 0 ; }
Finds a string in another string with a case insensitive test w/ length validation
Finds a string in another string with a case insensitive test w / length validation
// Check the entire string // Skip over non-matches // Check for match // We've run off the end; don't bother. // Found a match!