String filtering functions for some reason treat all input data as bytes. This causes incorrect behaviour of filter if string contains non-ascii letters (ex. polish '±', 'ê') encoded in unicode or utf-8.
WString Filter(const wchar *s, int (*filter)(int))
{
WString result;
while(*s) {
int c = (*filter)((char)*s++);
// ^^^^^^^^^ bug, should be wchar
if(c) result.Cat(c);
}
return result;
}
String Filter(const char *s, int (*filter)(int))
{
String result;
while(*s) {
int c = (*filter)((byte)*s++);
// ^^^^^^^ problem when s is UTF-8
if(c) result.Cat(c);
}
return result;
}
Thanks. First one fixed (hopefuly), second one I have to think through...