diff options
author | Olli Werwolff <qt-info@nokia.com> | 2010-05-26 09:24:03 +0200 |
---|---|---|
committer | Olli Werwolff <qt-info@nokia.com> | 2010-05-26 09:32:55 +0200 |
commit | fda556b47eaba6e1929eed1279084c57dd3fff57 (patch) | |
tree | 20c72bf02fe8a260d56e54c0c3e33dea5b1a2d35 | |
parent | 0a6a2861e9d041ee06af95365705bbd31592c18d (diff) |
Added function to use escaped characters when splitting parameters
In order to make the comma key configurable in the config files, we have
to be able to use escaped characters there.
Reviewed-by: ckamm
-rw-r--r-- | src/other/configurationreader.cpp | 24 | ||||
-rw-r--r-- | src/other/configurationreader.h | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/other/configurationreader.cpp b/src/other/configurationreader.cpp index 0e0da23..550f0be 100644 --- a/src/other/configurationreader.cpp +++ b/src/other/configurationreader.cpp @@ -119,7 +119,7 @@ bool ConfigurationReader::processLine(const QByteArray &line, DeviceData *device else if (parameter == "style") deviceData->style = value; else if (parameter == "button") { - QList<QByteArray> values = value.split(','); + QList<QByteArray> values = splitByUnescaped(value, ','); if (values.count() != 6) { errorMsg = tr("ConfigurationReader: button property requires six comma separated values\n" " button:keycode,keytext,x,y,width,height"); @@ -186,3 +186,25 @@ QString ConfigurationReader::errorMessageLines() const msg.append(str + '\n'); return msg; } + +QList<QByteArray> ConfigurationReader::splitByUnescaped(const QByteArray &arrayToSplit, QChar splitChar) +{ + QList<QByteArray> returnList; + + QByteArray arrayToAdd; + for(int i = 0; i < arrayToSplit.length(); i++) + { + if (arrayToSplit.at(i) == QLatin1Char('\\') && i < arrayToSplit.length() - 1) { + arrayToAdd.append(arrayToSplit.at(i + 1)); + i++; + } else if (arrayToSplit.at(i) == splitChar) { + returnList.append(arrayToAdd); + arrayToAdd.clear(); + } else { + arrayToAdd.append(arrayToSplit.at(i)); + } + } + if (!arrayToAdd.isEmpty()) + returnList.append(arrayToAdd); + return returnList; +} diff --git a/src/other/configurationreader.h b/src/other/configurationreader.h index 622b2bd..8f4a375 100644 --- a/src/other/configurationreader.h +++ b/src/other/configurationreader.h @@ -54,6 +54,7 @@ public: private: bool processLine(const QByteArray &line, DeviceData* deviceData, QString& errorMsg); void error(const QString& msg); + QList<QByteArray> splitByUnescaped(const QByteArray &arrayToSplit, QChar splitChar); private: QDir* mCurrentDir; |