Skip to content

Commit

Permalink
opt: beautify the output of dict server
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Dec 8, 2024
1 parent 8fd7d21 commit 72f6759
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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"(<a href="gdlookup://localhost/\1">\1</a>)" );
_articleText = _articleText.replace( refs, R"(<a href="gdlookup://localhost/\1">\1</a>)" );

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 );
Expand All @@ -673,18 +673,18 @@ class DictServerArticleRequest: public Dictionary::DataRequest
articleNewText += R"(<span class="dictd_phonetic">)" + phonetic_text + "</span>";
}
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 );
Expand All @@ -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( "<div class=\"dictd_article\">" ) + articleText.toUtf8().data() + "<br></div>";
articleData += string( "<div class=\"dictd_article\">" ) + _articleText.toUtf8().data() + "<br></div>";


if ( !articleData.empty() ) {
Expand Down

0 comments on commit 72f6759

Please sign in to comment.