This is the code that I have thanks to Bobby Bailey and Michael Barton.
char *strip_color(const char *string)
{
char buf[MAX_STRING_LENGTH];
char *newstr;
int count = 0;
char temp;
newstr = buf;
while (*string && count < (MAX_STRING_LENGTH - 1))
{
temp = *string++;
if (temp == '{')
{
temp = *string++;
if (temp == '{')
{
buf[count++] = '{';
buf[count++] = temp;
}
continue;
}
if (temp == '^')
{
temp = *string++;
if (temp == '^')
{
buf[count++] = '^';
buf[count++] = temp;
}
continue;
}
buf[count++] = temp;
}
buf[count] = '\0';
return newstr;
}
I am having a slight problem though, or at least I think it's a problem.
I am noticing a big increase in perms since I added this code ... the
only place I use this code is in the is_name function which I know is
called a ton of places. Here is my is_name function with the
strip_color calls in it.
bool is_name(char *str, char *namelist)
{
char name[MAX_INPUT_LENGTH], part[MAX_INPUT_LENGTH];
char *list, *string;
/* fix crash on NULL namelist */
if (namelist == NULL || namelist[0] == '\0')
return FALSE;
/* fixed to prevent is_name on "" returning TRUE */
if (str[0] == '\0')
return FALSE;
string = strip_color(str);
/* we need ALL parts of string to match part of namelist */
for (;;)
{
/* start parsing string */
str = one_argument(str, part);
if (part[0] == '\0')
return TRUE;
/* check to see if this is part of namelist */
list = strip_color(namelist);
for (;;)
{
/* start parsing namelist */
list = one_argument(list, name);
if (name[0] == '\0') /* this name was not found */
return FALSE;
if (!str_prefix(string, name))
return TRUE; /* full pattern match */
if (!str_prefix(part, name))
break;
}
}
}
I apologize for the length of this e-mail, but can anyone clue me in as
to why I would be receiving an increase in perms due to these functions?
Thanks in advance,
Matt Bradbury
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bobby
Hicks
Sent: Monday, January 13, 2003 10:46 PM
To: 'Hiddukel'; [email protected]
Subject: RE: stripping colors
This is actually pretty easy. If you are using the colour snippet by
Lope, you take the string, and step through it till you find a {, or
what ever ur colour code is, and skip the next character, and keep on
building.
IE
{DThis {Gis {Ba {Gsample {Ystring{C.{x
You input this into *input. Then you check input
if input++ == '{' { input++; output++ = input++; } else { output++ =
input++; }
Which, all of that is inside of a for loop, of course. Just make sure
you look for the '/0' at the end of the string so u can break out of the
for loop.
Hope this helps out in helping you create your own colour stripper.
Rheede
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of Hiddukel
> Sent: Monday, January 13, 2003 2:39 AM
> To: [email protected]
> Subject: stripping colors
>
>
> I have searched everywhere and can't find a snippet that has
> a function for stripping color codes from a string and
> returning the stripped version of the string. Can anyone
> help me out with some code for this? I'm using lopes colour
> codes so they are in the format {g etc.. Any help on this
> would be much appreciated.
>
> Matt Bradbury
--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom