summaryrefslogtreecommitdiffstats
path: root/libutil/src/cmdutils.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
commit2e0cbf393a5320dbf5448ca44a9b5905314b0be8 (patch)
tree4baac9cf015ca7b15d83de33c705e0d8d4497d30 /libutil/src/cmdutils.cpp
parent8808a8b108b82916eaf30f9aca50cd3ab16af230 (diff)
downloadMultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.gz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.lz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.xz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.zip
Massive renaming in the backend folder, all around restructure in the same.
Diffstat (limited to 'libutil/src/cmdutils.cpp')
-rw-r--r--libutil/src/cmdutils.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/libutil/src/cmdutils.cpp b/libutil/src/cmdutils.cpp
index 13db503d..80ba719d 100644
--- a/libutil/src/cmdutils.cpp
+++ b/libutil/src/cmdutils.cpp
@@ -24,6 +24,56 @@
namespace Util {
namespace Commandline {
+// commandline splitter
+QStringList splitArgs(QString args)
+{
+ QStringList argv;
+ QString current;
+ bool escape = false;
+ QChar inquotes;
+ for (int i=0; i<args.length(); i++)
+ {
+ QChar cchar = args.at(i);
+
+ // \ escaped
+ if (escape)
+ {
+ current += cchar;
+ escape = false;
+ // in "quotes"
+ }
+ else if (!inquotes.isNull())
+ {
+ if (cchar == 0x5C)
+ escape = true;
+ else if (cchar == inquotes)
+ inquotes = 0;
+ else
+ current += cchar;
+ // otherwise
+ }
+ else
+ {
+ if (cchar == 0x20)
+ {
+ if (!current.isEmpty())
+ {
+ argv << current;
+ current.clear();
+ }
+ }
+ else if (cchar == 0x22 || cchar == 0x27)
+ inquotes = cchar;
+ else
+ current += cchar;
+ }
+ }
+ if (!current.isEmpty())
+ argv << current;
+ return argv;
+}
+
+
Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle)
{
m_flagStyle = flagStyle;