summaryrefslogtreecommitdiff
path: root/src/discipline/Sport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/discipline/Sport.cpp')
-rw-r--r--src/discipline/Sport.cpp27
1 files changed, 27 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).