Added method to filter the last name (the one in CAPS). API reliability is questionable...
This commit is contained in:
parent
d399c562f5
commit
0445396ffa
|
@ -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).
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue