From c75c9cc74bbabbc701f73d1da190d615a8150d85 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sat, 19 Nov 2022 16:34:31 +0800 Subject: [PATCH] zim: move regex to globalregex --- base/globalregex.cc | 1 + base/globalregex.hh | 5 +++++ zim.cc | 15 ++++++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/base/globalregex.cc b/base/globalregex.cc index 203dde79..7cc7fb1d 100644 --- a/base/globalregex.cc +++ b/base/globalregex.cc @@ -65,3 +65,4 @@ QRegularExpression Mdx::styleElment( "(]*>)([\\w\\W]*?)(<\\/style>)", QRegularExpression::CaseInsensitiveOption); +QRegularExpression Zim::linkSpecialChar("[\\.\\/]"); diff --git a/base/globalregex.hh b/base/globalregex.hh index c5c025dc..fa8f8003 100644 --- a/base/globalregex.hh +++ b/base/globalregex.hh @@ -45,6 +45,11 @@ public: static QRegularExpression styleElment; }; +class Zim{ + public: + static QRegularExpression linkSpecialChar; +}; + } // namespace RX #endif // GLOBALREGEX_HH diff --git a/zim.cc b/zim.cc index 0f15802f..390c2be3 100644 --- a/zim.cc +++ b/zim.cc @@ -42,6 +42,7 @@ #include #include #include +#include "base/globalregex.hh" namespace Zim { @@ -883,10 +884,10 @@ string ZimDictionary::convert( const string & in ) } else{ //tag from list[3] - formatTag = tag;//tag.replace(QRegularExpression("[\\.\\/]"),"-"); + formatTag = tag; } - formatTag.replace(QRegularExpression("[\\.\\/]"),""); + formatTag.replace(RX::Zim::linkSpecialChar,""); vector< WordArticleLink > links; links = findArticles( gd::toWString( formatTag ) ); @@ -1489,7 +1490,7 @@ void ZimResourceRequest::run() sptr< Dictionary::DataRequest > ZimDictionary::getResource( string const & name ) { - auto formatedName = QString::fromStdString(name).replace(QRegularExpression("[\\.\\/]"),""); + auto formatedName = QString::fromStdString(name).replace(RX::Zim::linkSpecialChar,""); return new ZimResourceRequest( *this, formatedName.toStdString() ); } @@ -1641,7 +1642,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } if( !url.empty() ) { - auto formatedUrl = QString::fromStdString( url ).replace( QRegularExpression( "[\\.\\/]" ), "" ); + auto formatedUrl = QString::fromStdString( url ).replace( RX::Zim::linkSpecialChar, "" ); indexedWords.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } } @@ -1654,7 +1655,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } if( !url.empty() ) { - auto formatedUrl = QString::fromStdString( url ).replace( QRegularExpression( "[\\.\\/]" ), "" ); + auto formatedUrl = QString::fromStdString( url ).replace( RX::Zim::linkSpecialChar, "" ); indexedWords.addWord( Utf8::decode( formatedUrl.toStdString() ), n ); } } @@ -1662,7 +1663,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { - auto formatedUrl = QString::fromStdString(url).replace(QRegularExpression("[\\.\\/]"),""); + auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } } @@ -1701,7 +1702,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( { // url.insert( url.begin(), '/' ); // url.insert( url.begin(), nameSpace ); - auto formatedUrl = QString::fromStdString(url).replace(QRegularExpression("[\\.\\/]"),""); + auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } }