summaryrefslogtreecommitdiff
path: root/src/discipline
diff options
context:
space:
mode:
Diffstat (limited to 'src/discipline')
-rw-r--r--src/discipline/Sport.cpp27
-rw-r--r--src/discipline/Sport.h1
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);