diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-03 23:08:57 +0200 |
---|---|---|
committer | Steru <jerrydream111@gmail.com> | 2024-08-03 23:08:57 +0200 |
commit | 0445396ffa371cdc546d7198efc0677ad42b7aa5 (patch) | |
tree | 75d25de3010f9cfebacbe317641a77f91941e94f /src | |
parent | d399c562f5fad76ed8018c712a635f49715a8fed (diff) |
Added method to filter the last name (the one in CAPS). API reliability is questionable...
Diffstat (limited to 'src')
-rw-r--r-- | src/discipline/Sport.cpp | 27 | ||||
-rw-r--r-- | src/discipline/Sport.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/discipline/Sport.cpp b/src/discipline/Sport.cpp index 05ba95e..42e82aa 100644 --- a/src/discipline/Sport.cpp +++ b/src/discipline/Sport.cpp @@ -2,6 +2,7 @@ #include "Sport.h" #include <set> #include <algorithm> +#include <regex> #include <QJsonObject> #include <QJsonArray> @@ -29,6 +30,32 @@ bool compareMark(const QJsonValue &left, const QJsonValue &right) { return lMark < rMark; } +/** + * @brief Sport::lastName Reduce the full name to the part that is marked in capital letters (probably last name). + * @param competitors The competitors of one category. + */ +void Sport::lastName(QJsonArray& competitors) { + for (int i = 0; i < competitors.size(); ++i) { + string fullName = competitors[i].toObject()["name"].toString().toUtf8().constData(); + + regex r("[A-Z']{2,}"); + smatch m; + + regex_search(fullName, m, r); + + string lastName = ""; + for (string s : m) { + lastName = lastName + s + " "; + } + QJsonValue nameValue = QJsonValue(QString(lastName.substr(0, lastName.size() - 1).c_str())); + + QJsonObject comp(competitors[i].toObject()); + comp.remove("name"); + comp.insert("name", nameValue); + + competitors[i] = comp; + } +} /** * @brief Sport::getCategories Reads all possible categories (also called units). diff --git a/src/discipline/Sport.h b/src/discipline/Sport.h index 3b1c7f4..78968fe 100644 --- a/src/discipline/Sport.h +++ b/src/discipline/Sport.h @@ -24,6 +24,7 @@ public: QJsonArray getCompetitorsByCategory(QString category); // filter to change the current competitor array + void lastName(QJsonArray& competitors); void filterByName(QJsonArray& competitors, QString name); void filterByCountry(QJsonArray& competitors, QString nocShort); |