From 0445396ffa371cdc546d7198efc0677ad42b7aa5 Mon Sep 17 00:00:00 2001 From: Steru Date: Sat, 3 Aug 2024 23:08:57 +0200 Subject: Added method to filter the last name (the one in CAPS). API reliability is questionable... --- src/discipline/Sport.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/discipline/Sport.cpp') 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 #include +#include #include #include @@ -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). -- cgit v1.2.3