multi color code stripping from strings
sciogoon at gmail.com
sciogoon at gmail.com
Mon Jul 16 08:25:16 EDT 2007
It is possible to input such strings, that when stripped from color
code escape squences in one pass, would result in a color coded string
(which actually is expected to have no color codes).
For example ^^14n3vv|3 prints as ^[RED->]4n3vv|3
stripping ^1, because it's a color sequence: ^^14n3vv|3
one pass results in ^4n3vv|3, which prints as [BLUE->]n3vv|3
I recommend a function that processes the string until there is
nothing to strip. At the end of execution, the function guarantees no
remaining color codes.
void strip( char *str ) {
qboolean wasColored;
do {
wasColored = qfalse;
char *dst = str;
char *src = str;
while( *src ) {
if( *src == Q_COLOR_ESCAPE && *( src + 1 )
&& *( src + 1 ) != Q_COLOR_ESCAPE ) {
wasColored = qtrue;
src += 2;
while( *src ) {
if( *src == Q_COLOR_ESCAPE && *( src + 1 )
&& *( src + 1 ) != Q_COLOR_ESCAPE ) {
src += 2;
continue;
}
*dst++ = *src++;
}
*dst = '\0';
break;
}
dst++;
src++;
}
} while( wasColored );
}
More information about the quake3
mailing list