Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » string filtering bug
string filtering bug [message #22517] Tue, 21 July 2009 14:33 Go to previous message
Zbych is currently offline  Zbych
Messages: 326
Registered: July 2009
Senior Member
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;
}

 
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: Sat May 11 21:05:22 CEST 2024

Total time taken to generate the page: 0.01883 seconds