diff options
Diffstat (limited to 'csv')
| -rw-r--r-- | csv/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | csv/csv.cpp | 79 | ||||
| -rw-r--r-- | csv/csv.h | 10 | ||||
| -rw-r--r-- | csv/export.hpp | 11 | ||||
| -rw-r--r-- | csv/lang/de_DE.ts | 4 | ||||
| -rw-r--r-- | csv/lang/zh_CN.ts | 4 |
6 files changed, 45 insertions, 66 deletions
diff --git a/csv/CMakeLists.txt b/csv/CMakeLists.txt index 82595688..697b147f 100644 --- a/csv/CMakeLists.txt +++ b/csv/CMakeLists.txt @@ -1,2 +1 @@ -otr_module(csv) -target_link_libraries(opentrack-csv opentrack-api) +otr_module(csv STATIC) diff --git a/csv/csv.cpp b/csv/csv.cpp index 0f9072a7..6b4d0bcd 100644 --- a/csv/csv.cpp +++ b/csv/csv.cpp @@ -10,19 +10,16 @@ */ #include "csv.h" -#include "opentrack-library-path.h" +#include "compat/library-path.hpp" #include <QTextDecoder> #include <QFile> -#include <QCoreApplication> #include <QString> #include <QDebug> #include <utility> #include <algorithm> -using std::move; - -const QTextCodec* CSV::m_codec = QTextCodec::codecForName("System"); +const QTextCodec* const CSV::m_codec = QTextCodec::codecForName("UTF-8"); const QRegExp CSV::m_rx = QRegExp(QString("((?:(?:[^;\\n]*;?)|(?:\"[^\"]*\";?))*)?\\n?")); const QRegExp CSV::m_rx2 = QRegExp(QString("(?:\"([^\"]*)\";?)|(?:([^;]*);?)?")); @@ -48,7 +45,7 @@ QString CSV::readLine() } else { - static const QChar lf(QChar::LineFeed); + const QChar lf(QChar::LineFeed); while (m_pos < m_string.length()) if (m_string[m_pos++] == lf) @@ -79,7 +76,7 @@ bool CSV::parseLine(QStringList& ret) else if (m_rx2.cap(2).size() > 0) col = m_rx2.cap(2); - list << move(col); + list << col; if (col.size()) pos2 += m_rx2.matchedLength(); @@ -87,7 +84,7 @@ bool CSV::parseLine(QStringList& ret) pos2++; } } - ret = move(list); + ret = std::move(list); return true; } @@ -96,11 +93,13 @@ bool CSV::getGameData(int id, unsigned char* table, QString& gamename) for (int i = 0; i < 8; i++) table[i] = 0; + if (id != 0) + qDebug() << "csv: lookup game id" << id; + QString id_str(QString::number(id)); static const QString csv_path(OPENTRACK_BASE_PATH + - OPENTRACK_DOC_PATH + - QString("settings/facetracknoir supported games.csv")); + OPENTRACK_DOC_PATH "settings/facetracknoir supported games.csv"); QFile file(csv_path); @@ -112,13 +111,12 @@ bool CSV::getGameData(int id, unsigned char* table, QString& gamename) CSV csv(&file); - int lineno = 0; unsigned tmp[8]; unsigned fuzz[3]; QStringList gameLine; - while (lineno++, csv.parseLine(gameLine)) + for (int lineno = 0; csv.parseLine(gameLine); lineno++) { //qDebug() << "Column 0: " << gameLine.at(0); // No. //qDebug() << "Column 1: " << gameLine.at(1); // Game Name @@ -133,52 +131,41 @@ bool CSV::getGameData(int id, unsigned char* table, QString& gamename) { if (gameLine.at(6).compare(id_str, Qt::CaseInsensitive) == 0) { - const QString proto(move(gameLine.at(3))); - const QString name(move(gameLine.at(1))); - - const QByteArray id_cstr = gameLine.at(7).toLatin1(); - - if (proto == QString("V160")) - { - /* nothing */ - } - else if (id_cstr.length() != 22 || - sscanf(id_cstr.constData(), - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - fuzz + 2, - fuzz + 0, - tmp + 3, - tmp + 2, - tmp + 1, - tmp + 0, - tmp + 7, - tmp + 6, - tmp + 5, - tmp + 4, - fuzz + 1) != 11) - { + const QString& proto = gameLine[3]; + QString& name = gameLine[1]; + + const QByteArray id_cstr = gameLine[7].toLatin1(); + + auto do_scanf = [&]() { + return sscanf(id_cstr.constData(), + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + fuzz + 2, + fuzz + 0, + tmp + 3, tmp + 2, tmp + 1, tmp + 0, + tmp + 7, tmp + 6, tmp + 5, tmp + 4, + fuzz + 1); + }; + + if (proto == QStringLiteral("V160") || id_cstr.length() != 22) + (void)0; + else if (id_cstr.length() != 22 || do_scanf() != 11) qDebug() << "scanf failed" << lineno; - } else { + using uchar = unsigned char; for (int i = 0; i < 8; i++) - { - using t = unsigned char; - table[i] = t(tmp[i]); - } + table[i] = uchar(tmp[i]); } - //qDebug() << "csv: game-id" << id_str << "proto" << proto; - gamename = move(name); + gamename = std::move(name); return true; } } else - { qDebug() << "malformed csv line" << lineno; - } } - qDebug() << "unknown game connected" << id; + if (id) + qDebug() << "unknown game connected" << id; return false; } @@ -7,15 +7,12 @@ #include <QRegExp> #include <QtGlobal> -#include "export.hpp" - -class OTR_CSV_EXPORT CSV +class CSV { public: QString readLine(); bool parseLine(QStringList& ret); - void setCodec(const char* codecName); static bool getGameData(int gameID, unsigned char* table, QString& gamename); private: CSV(QIODevice* device); @@ -24,7 +21,6 @@ private: QString m_string; int m_pos; - static const QTextCodec* m_codec; - static const QRegExp m_rx; - static const QRegExp m_rx2; // Silly M$ compiler! It will generate an error if both of these variables are declared on the same line! (M$ Visual Studio Community 2015, Update 3) + static QTextCodec const* const m_codec; + static const QRegExp m_rx, m_rx2; }; diff --git a/csv/export.hpp b/csv/export.hpp deleted file mode 100644 index 7d7dbe29..00000000 --- a/csv/export.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// generates export.hpp for each module from compat/linkage.hpp - -#pragma once - -#include "compat/linkage-macros.hpp" - -#ifdef BUILD_CSV -# define OTR_CSV_EXPORT OTR_GENERIC_EXPORT -#else -# define OTR_CSV_EXPORT OTR_GENERIC_IMPORT -#endif diff --git a/csv/lang/de_DE.ts b/csv/lang/de_DE.ts new file mode 100644 index 00000000..1552582e --- /dev/null +++ b/csv/lang/de_DE.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="de_DE"> +</TS> diff --git a/csv/lang/zh_CN.ts b/csv/lang/zh_CN.ts new file mode 100644 index 00000000..e5ca8aa9 --- /dev/null +++ b/csv/lang/zh_CN.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="zh_CN"> +</TS> |
