Our own local, locale-independent version of isspace() is introduced and is

now used to handle utf8 strings. This fixes problems where the stock function
was mangling some utf8 strings under Windows.
This commit is contained in:
Konstantin Isakov 2009-02-02 00:56:58 +00:00
parent c8406798af
commit 33a2c8f705

View file

@ -86,6 +86,26 @@ namespace
return in; return in;
} }
// Since the standard isspace() is locale-specific, we need something
// that would never mess up our utf8 input. The stock one worked fine under
// Linux but was messing up strings under Windows.
bool isspace_c( int c )
{
switch( c )
{
case ' ':
case '\f':
case '\n':
case '\r':
case '\t':
case '\v':
return true;
default:
return false;
}
}
// Removes any leading or trailing whitespace // Removes any leading or trailing whitespace
void trimWs( string & word ) void trimWs( string & word )
{ {
@ -93,7 +113,7 @@ namespace
{ {
unsigned begin = 0; unsigned begin = 0;
while( begin < word.size() && isspace( word[ begin ] ) ) while( begin < word.size() && isspace_c( word[ begin ] ) )
++begin; ++begin;
if ( begin == word.size() ) // Consists of ws entirely? if ( begin == word.size() ) // Consists of ws entirely?
@ -104,7 +124,7 @@ namespace
// Doesn't consist of ws entirely, so must end with just isspace() // Doesn't consist of ws entirely, so must end with just isspace()
// condition. // condition.
while( isspace( word[ end - 1 ] ) ) while( isspace_c( word[ end - 1 ] ) )
--end; --end;
if ( end != word.size() || begin ) if ( end != word.size() || begin )