diff --git a/bgl.cc b/bgl.cc index ea632044..0bd062e3 100644 --- a/bgl.cc +++ b/bgl.cc @@ -118,26 +118,6 @@ 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 ) { @@ -145,7 +125,7 @@ namespace { unsigned begin = 0; - while( begin < word.size() && isspace_c( word[ begin ] ) ) + while( begin < word.size() && Utf8::isspace( word[ begin ] ) ) ++begin; if ( begin == word.size() ) // Consists of ws entirely? @@ -156,7 +136,7 @@ namespace // Doesn't consist of ws entirely, so must end with just isspace() // condition. - while( isspace_c( word[ end - 1 ] ) ) + while( Utf8::isspace( word[ end - 1 ] ) ) --end; if ( end != word.size() || begin ) diff --git a/dictdfiles.cc b/dictdfiles.cc index 93cb6083..cbd0a683 100644 --- a/dictdfiles.cc +++ b/dictdfiles.cc @@ -664,7 +664,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( char * eol = strchr( articleBody, '\n' ); // skip the first line (headword itself) if ( eol ) { - while( *eol && isspace( *eol ) ) ++eol; // skip spaces + while( *eol && Utf8::isspace( *eol ) ) ++eol; // skip spaces // use only the single line for the dictionary title char * endEol = strchr( eol, '\n' ); diff --git a/filetype.cc b/filetype.cc index e3b8975b..9eaad6f6 100644 --- a/filetype.cc +++ b/filetype.cc @@ -2,6 +2,7 @@ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #include "filetype.hh" +#include "utf8.hh" #include namespace Filetype { @@ -18,12 +19,12 @@ string simplifyString( string const & str ) size_t beginPos = 0; - while( beginPos < str.size() && isspace( str[ beginPos ] ) ) + while( beginPos < str.size() && Utf8::isspace( str[ beginPos ] ) ) ++beginPos; size_t endPos = str.size(); - while( endPos && isspace( str[ endPos - 1 ] ) ) + while( endPos && Utf8::isspace( str[ endPos - 1 ] ) ) --endPos; result.reserve( endPos - beginPos ); diff --git a/utf8.cc b/utf8.cc index 9d8e66dc..02db0926 100644 --- a/utf8.cc +++ b/utf8.cc @@ -155,4 +155,21 @@ wstring decode( string const & in ) throw( exCantDecode ) return wstring( &buffer.front(), result ); } +bool isspace( int c ) +{ + switch( c ) + { + case ' ': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + return true; + + default: + return false; + } +} + } diff --git a/utf8.hh b/utf8.hh index 723884d7..a48d9c6d 100644 --- a/utf8.hh +++ b/utf8.hh @@ -34,4 +34,9 @@ long decode( char const * in, size_t inSize, wchar * out ); string encode( wstring const & ) throw(); wstring decode( string const & ) throw( exCantDecode ); +/// 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( int c ); + }