mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
opt: refactor the escape(unescap)Amps (#1300)
* opt: refactor the escape(unescap)Amps * [autofix.ci] apply automated fixes --------- Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
1e0823147a
commit
8c87b934d4
|
@ -35,6 +35,20 @@ bool endsWithIgnoreCase( const string & str1, string str2 )
|
|||
return ( str1.size() >= (unsigned)str2.size() )
|
||||
&& ( strcasecmp( str1.c_str() + ( str1.size() - str2.size() ), str2.data() ) == 0 );
|
||||
}
|
||||
|
||||
QString escapeAmps( QString const & str )
|
||||
{
|
||||
QString result( str );
|
||||
result.replace( "&", "&&" );
|
||||
return result;
|
||||
}
|
||||
|
||||
QString unescapeAmps( QString const & str )
|
||||
{
|
||||
QString result( str );
|
||||
result.replace( "&&", "&" );
|
||||
return result;
|
||||
}
|
||||
} // namespace Utils
|
||||
|
||||
QString Utils::Path::combine( const QString & path1, const QString & path2 )
|
||||
|
|
|
@ -341,6 +341,10 @@ void removeDirectory( QString const & directory );
|
|||
void removeDirectory( string const & directory );
|
||||
} // namespace Fs
|
||||
|
||||
QString escapeAmps( QString const & str );
|
||||
|
||||
QString unescapeAmps( QString const & str );
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#endif // UTILS_HH
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "langcoder.hh"
|
||||
#include "language.hh"
|
||||
#include "metadata.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
|
@ -517,23 +518,6 @@ DictGroupsWidget::DictGroupsWidget( QWidget * parent ):
|
|||
setUsesScrollButtons( true );
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
QString escapeAmps( QString const & str )
|
||||
{
|
||||
QString result( str );
|
||||
result.replace( "&", "&&" );
|
||||
return result;
|
||||
}
|
||||
|
||||
QString unescapeAmps( QString const & str )
|
||||
{
|
||||
QString result( str );
|
||||
result.replace( "&&", "&" );
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void DictGroupsWidget::populate( Config::Groups const & groups,
|
||||
vector< sptr< Dictionary::Class > > const & allDicts_,
|
||||
|
@ -546,7 +530,7 @@ void DictGroupsWidget::populate( Config::Groups const & groups,
|
|||
|
||||
for ( int x = 0; x < groups.size(); ++x ) {
|
||||
const auto gr = new DictGroupWidget( this, *allDicts, groups[ x ] );
|
||||
addTab( gr, escapeAmps( groups[ x ].name ) );
|
||||
addTab( gr, Utils::escapeAmps( groups[ x ].name ) );
|
||||
connect( gr, &DictGroupWidget::showDictionaryInfo, this, &DictGroupsWidget::showDictionaryInfo );
|
||||
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
||||
|
||||
|
@ -569,7 +553,7 @@ Config::Groups DictGroupsWidget::makeGroups() const
|
|||
|
||||
for ( int x = 0; x < count(); ++x ) {
|
||||
result.push_back( dynamic_cast< DictGroupWidget & >( *widget( x ) ).makeGroup() );
|
||||
result.back().name = unescapeAmps( tabText( x ) );
|
||||
result.back().name = Utils::unescapeAmps( tabText( x ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -638,7 +622,7 @@ int DictGroupsWidget::addNewGroup( QString const & name )
|
|||
newGroup.id = nextId++;
|
||||
|
||||
const auto gr = new DictGroupWidget( this, *allDicts, newGroup );
|
||||
const int idx = insertTab( currentIndex() + 1, gr, escapeAmps( name ) );
|
||||
const int idx = insertTab( currentIndex() + 1, gr, Utils::escapeAmps( name ) );
|
||||
connect( gr, &DictGroupWidget::showDictionaryInfo, this, &DictGroupsWidget::showDictionaryInfo );
|
||||
|
||||
connect( gr->getModel(), &DictListModel::contentChanged, this, &DictGroupsWidget::tabDataChanged );
|
||||
|
@ -897,7 +881,7 @@ QString DictGroupsWidget::getCurrentGroupName() const
|
|||
const int current = currentIndex();
|
||||
|
||||
if ( current >= 0 )
|
||||
return unescapeAmps( tabText( current ) );
|
||||
return Utils::unescapeAmps( tabText( current ) );
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
@ -907,7 +891,7 @@ void DictGroupsWidget::renameCurrentGroup( QString const & name )
|
|||
const int current = currentIndex();
|
||||
|
||||
if ( current >= 0 )
|
||||
setTabText( current, escapeAmps( name ) );
|
||||
setTabText( current, Utils::escapeAmps( name ) );
|
||||
}
|
||||
|
||||
void DictGroupsWidget::removeCurrentGroup()
|
||||
|
|
|
@ -1814,8 +1814,7 @@ ArticleView * MainWindow::createNewTab( bool switchToIt, QString const & name )
|
|||
|
||||
int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
|
||||
|
||||
QString escaped = name;
|
||||
escaped.replace( "&", "&&" );
|
||||
QString escaped = Utils::escapeAmps( name );
|
||||
|
||||
ui.tabWidget->insertTab( index, view, escaped );
|
||||
mruList.append( dynamic_cast< QWidget * >( view ) );
|
||||
|
@ -1943,7 +1942,7 @@ void MainWindow::titleChanged( ArticleView * view, QString const & title )
|
|||
else {
|
||||
escaped = title;
|
||||
}
|
||||
escaped.replace( "&", "&&" );
|
||||
escaped = Utils::escapeAmps( escaped );
|
||||
|
||||
int index = ui.tabWidget->indexOf( view );
|
||||
if ( !escaped.isEmpty() )
|
||||
|
@ -4264,11 +4263,7 @@ void MainWindow::showFTSIndexingName( QString const & name )
|
|||
QString MainWindow::unescapeTabHeader( QString const & header )
|
||||
{
|
||||
// Reset table header to original headword
|
||||
|
||||
QString escaped = header;
|
||||
escaped.replace( "&&", "&" );
|
||||
|
||||
return escaped;
|
||||
return Utils::unescapeAmps( header );
|
||||
}
|
||||
|
||||
void MainWindow::addCurrentTabToFavorites()
|
||||
|
|
Loading…
Reference in a new issue