Color_String_Compare.txt
snippets · 1.0 KB · 2010-03-30
Color-aware string compare: matches two strings while ignoring color codes (uses ^ as the color character).
Download « Back to the snippets list
/*
* Color String Compare function
*
* compares string1 and string2 for matching of terms
* and disgards the color codes.
*
* Our mud uses ^ for the color code. If your mud
* uses { then replace '^' with '\{' in the function
*
* Valnir - Head Coder for Legend of the Nobles
* valnir@legendofthenobles.com
*
*/
/* put this in merc.h */
bool color_strcmp args( ( char *string1, char *string2 ) );
/* put this in string.c */
bool color_strcmp( char *string1, char *string2 )
{
char tmp1[MSL] = { '\0' };
char tmp2[MSL] = { '\0' };
int pos = 0;
while ( *string1 != '\0' )
{
if ( *string1 == '^' )
string1 += 2;
else
tmp1[pos++] = *(string1++);
}
tmp2[pos] = '\0';
pos = 0;
while ( *string2 != '\0' )
{
if ( *string2 == '^' )
string2 += 2;
else
tmp2[pos++] = *(string2++);
}
tmp2[pos] = '\0';
return str_cmp( tmp1, tmp2 );
}