Add strip_unprintable, a function that strips all unprintable characters from a string.
This commit is contained in:
parent
be6960363c
commit
114406d021
|
@ -77,4 +77,48 @@ strip_colour(char *string)
|
|||
return string;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
strip_unprintable(char *string)
|
||||
{
|
||||
char *c = string;
|
||||
char *c2 = string;
|
||||
char *last_non_space = NULL;
|
||||
|
||||
/* c is source, c2 is target */
|
||||
for(; c && *c; c++)
|
||||
switch (*c)
|
||||
{
|
||||
case 3:
|
||||
if(isdigit(c[1]))
|
||||
{
|
||||
c++;
|
||||
if(isdigit(c[1]))
|
||||
c++;
|
||||
if(c[1] == ',' && isdigit(c[2]))
|
||||
{
|
||||
c += 2;
|
||||
if(isdigit(c[1]))
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
*c2++ = *c;
|
||||
break;
|
||||
default:
|
||||
if (*c < 32)
|
||||
break;
|
||||
*c2++ = *c;
|
||||
last_non_space = c2;
|
||||
break;
|
||||
}
|
||||
|
||||
*c2 = '\0';
|
||||
|
||||
if(last_non_space)
|
||||
*last_non_space = '\0';
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue