Skip to content

Commit

Permalink
Merge pull request #1946 from shenlebantongying/clean/rm-gd-toWstring
Browse files Browse the repository at this point in the history
clean: remove redundant gd::toWString
  • Loading branch information
shenlebantongying authored Nov 13, 2024
2 parents 4539481 + 9db5867 commit 20fcea3
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ a11c9e3aeca4329e1982d8fe26bacbb21ab50ddf

# mass apply clang-tidy's modernize-use-using
d15081e723756eef053550dc9e06e31d7828dec3

# remove gd::toWString
c8af0450f1f7f8188004db96e3f53e7e33e2ccad
2 changes: 1 addition & 1 deletion src/article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void ArticleRequest::altSearchFinished()

vector< wstring > altsVector( alts.begin(), alts.end() );

wstring wordStd = gd::toWString( word );
wstring wordStd = word.toStdU32String();

if ( activeDicts.size() <= 1 ) {
articleSizeLimit = -1; // Don't collapse article if only one dictionary presented
Expand Down
2 changes: 1 addition & 1 deletion src/common/iconv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ gd::wstring Iconv::toWstring( char const * fromEncoding, void const * fromData,
Iconv ic( fromEncoding );

QString outStr = ic.convert( fromData, dataSize );
return gd::toWString( outStr );
return outStr.toStdU32String();
}

std::string Iconv::toUtf8( char const * fromEncoding, void const * fromData, size_t dataSize )
Expand Down
6 changes: 1 addition & 5 deletions src/common/wstring_qt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#include <QList>

namespace gd {
wstring toWString( QString const & in )
{
return in.toStdU32String();
}

// When convert non-BMP characters to wstring,the ending char maybe \0 .This method remove the tailing \0 from the wstring
// as \0 is sensitive in the index. This method will be only used with index related operations like store/query.
Expand Down Expand Up @@ -35,7 +31,7 @@ wstring removeTrailingZero( QString const & in )

wstring normalize( const wstring & str )
{
return toWString( QString::fromStdU32String( str ).normalized( QString::NormalizationForm_C ) );
return QString::fromStdU32String( str ).normalized( QString::NormalizationForm_C ).toStdU32String();
}


Expand Down
1 change: 0 additions & 1 deletion src/common/wstring_qt.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <QString>

namespace gd {
wstring toWString( QString const & );
wstring removeTrailingZero( wstring const & v );
wstring removeTrailingZero( QString const & in );
wstring normalize( wstring const & );
Expand Down
2 changes: 1 addition & 1 deletion src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class DictServerWordSearchRequest: public Dictionary::WordSearchRequest
if ( countn ) {
QMutexLocker _( &dataMutex );
for ( int x = 0; x < countn; x++ ) {
matches.emplace_back( gd::toWString( matchesList.at( x ) ) );
matches.emplace_back( matchesList.at( x ).toStdU32String() );
}
}
finish();
Expand Down
8 changes: 4 additions & 4 deletions src/dict/dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void DslDictionary::loadArticle( uint32_t address,

if ( !articleBody ) {
// throw exCantReadFile( getDictionaryFilenames()[ 0 ] );
articleData = U"\n\r\t" + gd::toWString( QString( "DICTZIP error: " ) + dict_error_str( dz ) );
articleData = U"\n\r\tDICTZIP error: " + QString( dict_error_str( dz ) ).toStdU32String();
}
else {
try {
Expand Down Expand Up @@ -966,7 +966,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
if ( n >= 0 ) {
int n2 = attr.indexOf( '\"', n + 6 );
if ( n2 > 0 ) {
quint32 id = dslLanguageToId( gd::toWString( attr.mid( n + 6, n2 - n - 6 ) ) );
quint32 id = dslLanguageToId( attr.mid( n + 6, n2 - n - 6 ).toStdU32String() );
langcode = LangCoder::intToCode2( id ).toStdString();
}
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ QString const & DslDictionary::getDescription()
for ( ;; ) {
data.clear();
langStr = str.mid( 10 ).replace( '\"', ' ' ).trimmed();
annLang = LangCoder::findIdForLanguage( gd::toWString( langStr ) );
annLang = LangCoder::findIdForLanguage( langStr.toStdU32String() );
do {
str = annStream.readLine();
if ( str.left( 10 ).compare( "#LANGUAGE " ) == 0 ) {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,

if ( haveInsidedCards ) {
// Use base DSL parser for articles with insided cards
ArticleDom dom( gd::toWString( text ), getName(), articleHeadword );
ArticleDom dom( text.toStdU32String(), getName(), articleHeadword );
text = QString::fromStdU32String( dom.root.renderAsText( true ) );
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/dict/epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ void EpwingWordSearchRequest::findMatches()
QMutexLocker _( &dataMutex );

for ( const auto & headword : headwords )
addMatch( gd::toWString( headword ) );
addMatch( headword.toStdU32String() );

break;
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ void addWordToChunks( Epwing::Book::EpwingHeadword & head,
chunks.addToBlock( &head.page, sizeof( head.page ) );
chunks.addToBlock( &head.offset, sizeof( head.offset ) );

wstring hw = gd::toWString( head.headword );
wstring hw = head.headword.toStdU32String();

indexedWords.addWord( hw, offset );
wordCount++;
Expand Down
2 changes: 1 addition & 1 deletion src/dict/epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ void EpwingBook::fixHeadword( QString & headword )
// return;
//}

gd::wstring folded = Folding::applyPunctOnly( gd::toWString( fixed ) );
gd::wstring folded = Folding::applyPunctOnly( fixed.toStdU32String() );
//fixed = QString::fromStdU32String( folded );

//if( isHeadwordCorrect( fixed ) )
Expand Down
4 changes: 2 additions & 2 deletions src/dict/hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ QList< wstring > suggest( wstring & word, QMutex & hunspellMutex, Hunspell & hun

auto match = cutStem.match( suggestion.trimmed() );
if ( match.hasMatch() ) {
wstring alt = gd::toWString( match.captured( 1 ) );
wstring alt = match.captured( 1 ).toStdU32String();

if ( Folding::applySimpleCaseOnly( alt ) != lowercasedWord ) // No point in providing same word
{
Expand Down Expand Up @@ -643,7 +643,7 @@ wstring decodeFromHunspell( Hunspell & hunspell, char const * str )
size_t outLeft = result.size() * sizeof( wchar );

QString convStr = conv.convert( in, inLeft );
return gd::toWString( convStr );
return convStr.toStdU32String();
}
} // namespace

Expand Down
8 changes: 4 additions & 4 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void MddResourceRequest::run()
data.push_back( '\0' );
QString target =
MdictParser::toUtf16( "UTF-16LE", &data.front() + sizeof( pattern ), data.size() - sizeof( pattern ) );
resourceName = gd::toWString( target.trimmed() );
resourceName = target.trimmed().toStdU32String();
continue;
}
}
Expand Down Expand Up @@ -1200,7 +1200,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
data.push_back( '\0' );
QString target =
MdictParser::toUtf16( "UTF-16LE", &data.front() + sizeof( pattern ), data.size() - sizeof( pattern ) );
resourceName = gd::toWString( target.trimmed() );
resourceName = target.trimmed().toStdU32String();
continue;
}
break;
Expand Down Expand Up @@ -1249,14 +1249,14 @@ static void addEntryToIndex( QString const & word, uint32_t offset, IndexedWords
{
// Strip any leading or trailing whitespaces
QString wordTrimmed = word.trimmed();
indexedWords.addWord( gd::toWString( wordTrimmed ), offset );
indexedWords.addWord( wordTrimmed.toStdU32String(), offset );
}

static void addEntryToIndexSingle( QString const & word, uint32_t offset, IndexedWords & indexedWords )
{
// Strip any leading or trailing whitespaces
QString wordTrimmed = word.trimmed();
indexedWords.addSingleWord( gd::toWString( wordTrimmed ), offset );
indexedWords.addSingleWord( wordTrimmed.toStdU32String(), offset );
}

class ArticleHandler: public MdictParser::RecordHandler
Expand Down
2 changes: 1 addition & 1 deletion src/dict/mediawiki.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void MediaWikiWordSearchRequest::downloadFinished()

qDebug() << "matches" << matches.size();
for ( int x = 0; x < nl.length(); ++x ) {
matches.emplace_back( gd::toWString( nl.item( x ).toElement().attribute( "title" ) ) );
matches.emplace_back( nl.item( x ).toElement().attribute( "title" ).toStdU32String() );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dict/programs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void ProgramWordSearchRequest::instanceFinished( QByteArray output, QString erro
QStringList result = QString::fromUtf8( output ).split( "\n", Qt::SkipEmptyParts );

for ( const auto & x : result ) {
matches.push_back( Dictionary::WordMatch( gd::toWString( x ) ) );
matches.push_back( Dictionary::WordMatch( x.toStdU32String() ) );
}

if ( !error.isEmpty() ) {
Expand Down
6 changes: 3 additions & 3 deletions src/dict/slob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1315,10 +1315,10 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|| contentType.startsWith( "text/plain", Qt::CaseInsensitive ) ) {
//Article
if ( maxHeadwordsToExpand && entries > maxHeadwordsToExpand ) {
indexedWords.addSingleWord( gd::toWString( refEntry.key ), offsets[ i ].second );
indexedWords.addSingleWord( refEntry.key.toStdU32String(), offsets[ i ].second );
}
else {
indexedWords.addWord( gd::toWString( refEntry.key ), offsets[ i ].second );
indexedWords.addWord( refEntry.key.toStdU32String(), offsets[ i ].second );
}

wordCount += 1;
Expand All @@ -1330,7 +1330,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
}
}
else {
indexedResources.addSingleWord( gd::toWString( refEntry.key ), offsets[ i ].second );
indexedResources.addSingleWord( refEntry.key.toStdU32String(), offsets[ i ].second );
}
}
sf.clearRefOffsets();
Expand Down
2 changes: 1 addition & 1 deletion src/dict/sounddir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void addDir( QDir const & baseDir,
const uint32_t articleOffset = chunks.startNewBlock();
chunks.addToBlock( fileName.c_str(), fileName.size() + 1 );

wstring name = gd::toWString( i->fileName() );
wstring name = i->fileName().toStdU32String();

const wstring::size_type pos = name.rfind( L'.' );

Expand Down
2 changes: 1 addition & 1 deletion src/dict/utils/indexedzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32
// System locale
if ( localeCodec ) {
QString name = localeCodec->toUnicode( entry.fileName.constData(), entry.fileName.size() );
nameInSystemLocale = gd::toWString( name );
nameInSystemLocale = name.toStdU32String();
if ( !nameInSystemLocale.empty() ) {
zipFileNames.addSingleWord( nameInSystemLocale, entry.localHeaderOffset );

Expand Down
6 changes: 3 additions & 3 deletions src/dict/xdxf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ void indexArticle( GzippedFile & gzFile,
// Add words to index

for ( const auto & word : words ) {
indexedWords.addWord( gd::toWString( word ), offset );
indexedWords.addWord( word.toStdU32String(), offset );
}

++articleCount;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
while ( !( stream.isEndElement() && stream.name() == u"abbr_def" ) || !stream.atEnd() ) {
if ( stream.isStartElement() && stream.name() == u"abbr_k" ) {
s = readElementText( stream );
keys.push_back( gd::toWString( s ) );
keys.push_back( s.toStdU32String() );
}
else if ( stream.isStartElement() && stream.name() == u"abbr_v" ) {
s = readElementText( stream );
Expand All @@ -1246,7 +1246,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
while ( !( stream.isEndElement() && stream.name() == u"abr_def" ) || !stream.atEnd() ) {
if ( stream.isStartElement() && stream.name() == u"k" ) {
s = readElementText( stream );
keys.push_back( gd::toWString( s ) );
keys.push_back( s.toStdU32String() );
}
else if ( stream.isStartElement() && stream.name() == u"v" ) {
s = readElementText( stream );
Expand Down
2 changes: 1 addition & 1 deletion src/dict/xdxf2html.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ string convert( string const & in,

// if( type == XDXF && dictPtr != NULL && !el.hasAttribute( "start" ) )
if ( dictPtr != NULL && !el.hasAttribute( "start" ) ) {
string filename = Utf8::encode( gd::toWString( el.text() ) );
string filename = Utf8::encode( el.text().toStdU32String() );

if ( Filetype::isNameOfPicture( filename ) ) {
QUrl url;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ void ArticleView::doubleClicked( QPoint pos )

emit sendWordToInputLine( selectedText );
// Do some checks to make sure there's a sensible selection indeed
if ( Folding::applyWhitespaceOnly( gd::toWString( selectedText ) ).size() && selectedText.size() < 60 ) {
if ( Folding::applyWhitespaceOnly( selectedText.toStdU32String() ).size() && selectedText.size() < 60 ) {
// Initiate translation
Qt::KeyboardModifiers kmod = QApplication::keyboardModifiers();
if ( kmod & ( Qt::ControlModifier | Qt::ShiftModifier ) ) { // open in new tab
Expand Down
2 changes: 1 addition & 1 deletion src/wordfinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void WordFinder::startSearch()
allWordWritings.resize( 1 );
}

allWordWritings[ 0 ] = gd::toWString( inputWord );
allWordWritings[ 0 ] = inputWord.toStdU32String();

for ( const auto & inputDict : *inputDicts ) {
vector< wstring > writings = inputDict->getAlternateWritings( allWordWritings[ 0 ] );
Expand Down

0 comments on commit 20fcea3

Please sign in to comment.