From dbb11e293b92d375214b51fa3abe24bd0cc33113 Mon Sep 17 00:00:00 2001
From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com>
Date: Wed, 26 Jul 2023 23:03:03 +0800
Subject: [PATCH] opt: optimize the process of audio link which start with
double // (#1008)
* opt: optimize the process of audio link which start with double //
* [autofix.ci] apply automated fixes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
---
src/audiolink.cc | 16 ++++++++++------
src/audiolink.hh | 3 ++-
src/dict/mediawiki.cc | 15 ++++++---------
3 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/audiolink.cc b/src/audiolink.cc
index 19cd804e..720bcc52 100644
--- a/src/audiolink.cc
+++ b/src/audiolink.cc
@@ -6,13 +6,17 @@
std::string addAudioLink( std::string const & url, std::string const & dictionaryId )
{
- if ( url.empty() || url.length() < 2 )
- return {};
- GlobalBroadcaster::instance()->pronounce_engine.sendAudio(
- dictionaryId,
- QString::fromStdString( url.substr( 1, url.length() - 2 ) ) );
+ return addAudioLink( QString::fromStdString( url ), dictionaryId );
+}
- return std::string( "" );
+std::string addAudioLink( QString const & url, std::string const & dictionaryId )
+{
+ if ( url.isEmpty() || url.length() < 2 )
+ return {};
+ GlobalBroadcaster::instance()->pronounce_engine.sendAudio( dictionaryId, url.mid( 1, url.length() - 2 ) );
+
+ return std::string( "" );
}
std::string makeAudioLinkScript( std::string const & url, std::string const & dictionaryId )
diff --git a/src/audiolink.hh b/src/audiolink.hh
index edb65317..314932a6 100644
--- a/src/audiolink.hh
+++ b/src/audiolink.hh
@@ -5,6 +5,7 @@
#define __AUDIOLINK_HH_INCLUDED__
+#include
#include
/// Adds a piece of javascript to save the given audiolink to a special
@@ -13,7 +14,7 @@
/// The url should be escaped and surrounded by quotes.
/// The dictionary id is used to make active dictionary feature work.
std::string addAudioLink( std::string const & url, std::string const & dictionaryId );
-
+std::string addAudioLink( QString const & url, std::string const & dictionaryId );
std::string makeAudioLinkScript( std::string const & url, std::string const & dictionaryId );
#endif
diff --git a/src/dict/mediawiki.cc b/src/dict/mediawiki.cc
index 69c7b5d2..fafc834b 100644
--- a/src/dict/mediawiki.cc
+++ b/src/dict/mediawiki.cc
@@ -558,7 +558,12 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
QRegularExpressionMatch match2 = reg2.match( tag );
if ( match2.hasMatch() ) {
QString ref = match2.captured( 1 );
- QString audio_url = "dictPtr->getId() );
+ QString audio_url = QString::fromStdString( script ) + ")";
articleNewString += audio_url;
}
@@ -571,14 +576,6 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
articleNewString.clear();
}
- // audio url like this dictPtr->getId() )
- + "