mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
refactor getqueryword
This commit is contained in:
parent
ccd8ace0ec
commit
5f856bf2ae
|
@ -513,11 +513,10 @@ void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
|
|||
request.setUrl( url );
|
||||
|
||||
//all the url reached here must be either gdlookup or bword scheme.
|
||||
auto queryWord = Utils::Url::getQueryWord( url );
|
||||
auto word = queryWord.second;
|
||||
auto [valid, word] = Utils::Url::getQueryWord( url );
|
||||
// or the condition can be (!queryWord.first || word.isEmpty())
|
||||
// ( queryWord.first && word.isEmpty() ) is only part of the above condition.
|
||||
if( queryWord.first && word.isEmpty() )
|
||||
if( valid && word.isEmpty() )
|
||||
{
|
||||
// invalid gdlookup url.
|
||||
return;
|
||||
|
|
|
@ -1113,9 +1113,8 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
|
|||
audioPlayer->stop();
|
||||
qDebug() << "open link url:" << url;
|
||||
|
||||
auto queryWord = Utils::Url::getQueryWord( url );
|
||||
auto word = queryWord.second;
|
||||
if( queryWord.first && word.isEmpty() )
|
||||
auto [valid, word] = Utils::Url::getQueryWord( url );
|
||||
if( valid && word.isEmpty() )
|
||||
{
|
||||
// invalid gdlookup url.
|
||||
return;
|
||||
|
|
19
utils.hh
19
utils.hh
|
@ -224,7 +224,24 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url )
|
|||
if( url.scheme().compare( "bword" ) == 0 )
|
||||
{
|
||||
validScheme = true;
|
||||
word = url.path().mid( 1 );
|
||||
|
||||
auto path = url.path();
|
||||
// url like this , bword:word or bword://localhost/word
|
||||
if( !path.isEmpty() )
|
||||
{
|
||||
//url,bword://localhost/word
|
||||
if( path.startsWith( "/" ) )
|
||||
word = url.path().mid( 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// url looks like this, bword://word,or bword://localhost
|
||||
auto host = url.host();
|
||||
if( host != "localhost" )
|
||||
{
|
||||
word = host;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::make_pair( validScheme, word );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue