mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Use own isspace() implementation in all places
This commit is contained in:
parent
a6d7e204eb
commit
65eaeabb1d
24
bgl.cc
24
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 )
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include "filetype.hh"
|
||||
#include "utf8.hh"
|
||||
#include <ctype.h>
|
||||
|
||||
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 );
|
||||
|
|
17
utf8.cc
17
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
5
utf8.hh
5
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 );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue