summaryrefslogtreecommitdiffstats
path: root/src/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Util.cpp')
-rw-r--r--src/Util.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Util.cpp b/src/Util.cpp
index 8b5bc67..014f1f8 100644
--- a/src/Util.cpp
+++ b/src/Util.cpp
@@ -82,5 +82,54 @@ namespace Util {
return ret;
}
+ QString joinEscape(const QStringList &list, const QChar joinChar, const QChar escapeChar)
+ {
+ QString ret;
+ bool first = true;
+ foreach(const QString& part, list)
+ {
+ if(!first)
+ {
+ ret.append(joinChar);
+ }
+ else
+ {
+ first = false;
+ }
+ ret.append(escape(part, escapeChar, joinChar));
+ }
+ return ret;
+ }
+
+ QStringList splitEscaped(const QString &joined, const QChar splitChar, const QChar escapeChar)
+ {
+ QStringList ret;
+
+ int partPos = 0;
+ bool escaped = false;
+ for(int i = 0; i < joined.length(); ++i)
+ {
+ QChar c = joined.at(i);
+ if(!escaped)
+ {
+ if(c == escapeChar)
+ {
+ escaped = true;
+ }
+ else if(c == splitChar)
+ {
+ ret.append(Util::unescape(joined.mid(partPos, i - partPos), escapeChar));
+ partPos = i + 1;
+ }
+ }
+ else
+ {
+ escaped = false;
+ }
+ }
+ ret.append(Util::unescape(joined.mid(partPos), escapeChar));
+
+ return ret;
+ }
}