diff --git a/src/bgl.cc b/src/bgl.cc index 22a6cba8..92a6ff55 100644 --- a/src/bgl.cc +++ b/src/bgl.cc @@ -86,6 +86,26 @@ namespace 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 void trimWs( string & word ) { @@ -93,7 +113,7 @@ namespace { unsigned begin = 0; - while( begin < word.size() && isspace( word[ begin ] ) ) + while( begin < word.size() && isspace_c( word[ begin ] ) ) ++begin; 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() // condition. - while( isspace( word[ end - 1 ] ) ) + while( isspace_c( word[ end - 1 ] ) ) --end; if ( end != word.size() || begin )