mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Compare commits
4 commits
243ce1c7b7
...
c04336fbfa
Author | SHA1 | Date | |
---|---|---|---|
c04336fbfa | |||
fbec70e41a | |||
daf2e81ae3 | |||
f59b04565a |
|
@ -20,41 +20,23 @@ bool isCombiningMark( wchar ch )
|
||||||
|
|
||||||
wstring apply( wstring const & in, bool preserveWildcards )
|
wstring apply( wstring const & in, bool preserveWildcards )
|
||||||
{
|
{
|
||||||
//remove space and accent;
|
// remove diacritics (normalization), white space, punt,
|
||||||
auto withPunc = QString::fromStdU32String( in )
|
auto temp = QString::fromStdU32String( in )
|
||||||
.normalized( QString::NormalizationForm_KD )
|
.normalized( QString::NormalizationForm_KD )
|
||||||
.remove( RX::markSpace )
|
.remove( RX::markSpace )
|
||||||
.toStdU32String();
|
.removeIf( [ preserveWildcards ]( const QChar & ch ) -> bool {
|
||||||
|
return ch.isPunct()
|
||||||
//First, strip diacritics and apply ws/punctuation removal
|
&& !( preserveWildcards && ( ch == '\\' || ch == '?' || ch == '*' || ch == '[' || ch == ']' ) );
|
||||||
wstring withoutDiacritics;
|
} )
|
||||||
|
.toStdU32String();
|
||||||
withoutDiacritics.reserve( withPunc.size() );
|
// case folding
|
||||||
|
std::u32string caseFolded;
|
||||||
|
caseFolded.reserve( temp.size() );
|
||||||
for ( auto const & ch : withPunc ) {
|
|
||||||
|
|
||||||
if ( !isPunct( ch )
|
|
||||||
|| ( preserveWildcards && ( ch == '\\' || ch == '?' || ch == '*' || ch == '[' || ch == ']' ) ) ) {
|
|
||||||
withoutDiacritics.push_back( ch );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Now, fold the case
|
|
||||||
|
|
||||||
wstring caseFolded;
|
|
||||||
|
|
||||||
caseFolded.reserve( withoutDiacritics.size() * foldCaseMaxOut );
|
|
||||||
|
|
||||||
wchar const * nextChar = withoutDiacritics.data();
|
|
||||||
|
|
||||||
wchar buf[ foldCaseMaxOut ];
|
wchar buf[ foldCaseMaxOut ];
|
||||||
|
for ( const char32_t ch : temp ) {
|
||||||
for ( size_t left = withoutDiacritics.size(); left--; ) {
|
auto n = foldCase( ch, buf );
|
||||||
caseFolded.append( buf, foldCase( *nextChar++, buf ) );
|
caseFolded.append( buf, n );
|
||||||
}
|
}
|
||||||
|
|
||||||
return caseFolded;
|
return caseFolded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -538,14 +538,22 @@ void DictServerWordSearchRequest::readMatchData( QByteArray & reply )
|
||||||
if ( word.endsWith( '\"' ) ) {
|
if ( word.endsWith( '\"' ) ) {
|
||||||
word.chop( 1 );
|
word.chop( 1 );
|
||||||
}
|
}
|
||||||
if ( word[ 0 ] == '\"' ) {
|
if ( word.startsWith( '\"' ) ) {
|
||||||
word = word.mid( 1 );
|
word = word.mid( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
this->addMatchedWord( word );
|
if ( !word.isEmpty() ) {
|
||||||
|
this->addMatchedWord( word );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reply = this->dictImpl->socket.readLine();
|
constexpr int halfSecond = 500;
|
||||||
|
if ( this->dictImpl->socket.waitForReadyRead( halfSecond ) ) {
|
||||||
|
reply = this->dictImpl->socket.readLine();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
} while ( true );
|
} while ( true );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue