U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » string filtering bug
Re: string filtering bug [message #22520 is a reply to message #22517] Tue, 21 July 2009 17:17 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Zbych wrote on Tue, 21 July 2009 08:33

Hi,

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...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: EOL problem
Next Topic: Environment variables code page
Goto Forum:
  


Current Time: Sun Apr 26 10:09:38 GMT+2 2026

Total time taken to generate the page: 0.00563 seconds