mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
* Translate curly apostrophe to ASCII apostrophe (#3395) Treats the curly apostrophe as a straight apostrophe when searching in the deck editor search bar. * Moved logic for handeling translation to CardDatabaseDisplayModel. This implementation was done with strings instead of characters because the curly apostrophes and quotes are considered multi-characters. Thus, the method of iterating through the string and replacing the characters with the proper translations was difficult to cleanly implement. * clang-tidy modifications * Implemented faster algorithm for string translation. Optimized the algorithm for string translation, before it would compute in O(N*M) time where N is the size of the string and M is the size of the translation table. Now it will compute in O(N) time where N is the length of the string. * Renaming variables and methods. * Fixed character literal type, was unicode, is now wide.
This commit is contained in:
parent
eb4b1e74f1
commit
cf9fdcd09e
2 changed files with 22 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "carddatabasemodel.h"
|
||||
#include "filtertree.h"
|
||||
#include <QMap>
|
||||
|
||||
#define CARDDBMODEL_COLUMNS 6
|
||||
|
||||
|
|
@ -17,6 +18,11 @@ CardDatabaseModel::~CardDatabaseModel()
|
|||
{
|
||||
}
|
||||
|
||||
QMap<wchar_t, wchar_t> CardDatabaseDisplayModel::characterTranslation = {{L'“', L'\"'},
|
||||
{L'”', L'\"'},
|
||||
{L'‘', L'\''},
|
||||
{L'’', L'\''}};
|
||||
|
||||
int CardDatabaseModel::rowCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return cardList.size();
|
||||
|
|
@ -324,6 +330,16 @@ void CardDatabaseDisplayModel::filterTreeChanged()
|
|||
invalidate();
|
||||
}
|
||||
|
||||
const QString CardDatabaseDisplayModel::sanitizeCardName(const QString &dirtyName, const QMap<wchar_t, wchar_t> &table)
|
||||
{
|
||||
std::wstring toReturn = dirtyName.toStdWString();
|
||||
for (wchar_t &ch : toReturn) {
|
||||
if (table.contains(ch)) {
|
||||
ch = table.value(ch);
|
||||
}
|
||||
}
|
||||
return QString::fromStdWString(toReturn);
|
||||
}
|
||||
TokenDisplayModel::TokenDisplayModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue