From 72f6759827c6f87ee10bb713034494cfb1ed680a Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sun, 8 Dec 2024 09:01:48 +0800 Subject: [PATCH] opt: beautify the output of dict server --- src/dict/dictserver.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/dict/dictserver.cc b/src/dict/dictserver.cc index f549e5b59..6de66ce16 100644 --- a/src/dict/dictserver.cc +++ b/src/dict/dictserver.cc @@ -592,18 +592,18 @@ class DictServerArticleRequest: public Dictionary::DataRequest cancel(); } ); - connect( this, &DictServerArticleRequest::finishedArticle, this, [ this ]( QString articleText ) { + connect( this, &DictServerArticleRequest::finishedArticle, this, [ this ]( QString _articleText ) { if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) { cancel(); return; } - //modify the articleText,remove extra lines[start with 15X etc.] - QList< QString > lines = articleText.split( "\n", Qt::SkipEmptyParts ); + //modify the _articleText,remove extra lines[start with 15X etc.] + QList< QString > lines = _articleText.split( "\n", Qt::SkipEmptyParts ); - QStringList resultStr; + QString resultStr; - // proccess the line + // process the line static QRegularExpression leadingRespCode( "^\\d{3} " ); uint32_t leadingSpaceCount = 0; uint32_t firstLeadingSpaceCount = 0; @@ -612,7 +612,7 @@ class DictServerArticleRequest: public Dictionary::DataRequest if ( leadingRespCode.match( line ).hasMatch() ) { continue; } - // ignore . endline + // ignore dot(.),the end line character if ( line.trimmed() == "." ) { break; } @@ -651,20 +651,20 @@ class DictServerArticleRequest: public Dictionary::DataRequest articleStr = Html::preformat( resultStr.toUtf8().data() ); } - articleText = QString::fromUtf8( articleStr.c_str(), articleStr.size() ); + _articleText = QString::fromUtf8( articleStr.c_str(), articleStr.size() ); int pos; if ( !contentInHtml ) { - articleText = articleText.replace( refs, R"(\1)" ); + _articleText = _articleText.replace( refs, R"(\1)" ); pos = 0; QString articleNewText; // Handle phonetics - QRegularExpressionMatchIterator it = phonetic.globalMatch( articleText ); + QRegularExpressionMatchIterator it = phonetic.globalMatch( _articleText ); while ( it.hasNext() ) { QRegularExpressionMatch match = it.next(); - articleNewText += articleText.mid( pos, match.capturedStart() - pos ); + articleNewText += _articleText.mid( pos, match.capturedStart() - pos ); pos = match.capturedEnd(); QString phonetic_text = match.captured( 1 ); @@ -673,18 +673,18 @@ class DictServerArticleRequest: public Dictionary::DataRequest articleNewText += R"()" + phonetic_text + ""; } if ( pos ) { - articleNewText += articleText.mid( pos ); - articleText = articleNewText; + articleNewText += _articleText.mid( pos ); + _articleText = articleNewText; articleNewText.clear(); } // Handle links pos = 0; - it = links.globalMatch( articleText ); + it = links.globalMatch( _articleText ); while ( it.hasNext() ) { QRegularExpressionMatch match = it.next(); - articleNewText += articleText.mid( pos, match.capturedStart() - pos ); + articleNewText += _articleText.mid( pos, match.capturedStart() - pos ); pos = match.capturedEnd(); QString link = match.captured( 1 ); @@ -698,13 +698,13 @@ class DictServerArticleRequest: public Dictionary::DataRequest articleNewText += newLink; } if ( pos ) { - articleNewText += articleText.mid( pos ); - articleText = articleNewText; + articleNewText += _articleText.mid( pos ); + _articleText = articleNewText; articleNewText.clear(); } } - articleData += string( "
" ) + articleText.toUtf8().data() + "
"; + articleData += string( "
" ) + _articleText.toUtf8().data() + "
"; if ( !articleData.empty() ) {