summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-string-escape-util.cpp16
-rw-r--r--source/core/slang-string-escape-util.h3
2 files changed, 19 insertions, 0 deletions
diff --git a/source/core/slang-string-escape-util.cpp b/source/core/slang-string-escape-util.cpp
index 0645d94ba..c079b8b39 100644
--- a/source/core/slang-string-escape-util.cpp
+++ b/source/core/slang-string-escape-util.cpp
@@ -1099,6 +1099,22 @@ StringEscapeUtil::Handler* StringEscapeUtil::getHandler(Style style)
}
}
+/* static */ UnownedStringSlice StringEscapeUtil::maybeUnquoteCommandLineArg(
+ UnownedStringSlice slice)
+{
+ // If the slice is quoted, unquote it, else return as is
+ if (slice.startsWith("\'") || slice.startsWith("\""))
+ {
+ const Index len = slice.getLength();
+ if (len >= 2 && slice[len - 1] == slice[0])
+ {
+ // Unquote it
+ return UnownedStringSlice(slice.begin() + 1, len - 2);
+ }
+ }
+ return slice;
+}
+
/* static */ bool StringEscapeUtil::isQuoted(char quoteChar, UnownedStringSlice& slice)
{
const Index len = slice.getLength();
diff --git a/source/core/slang-string-escape-util.h b/source/core/slang-string-escape-util.h
index ece8de79f..07b3bcc3d 100644
--- a/source/core/slang-string-escape-util.h
+++ b/source/core/slang-string-escape-util.h
@@ -79,6 +79,9 @@ struct StringEscapeUtil
return isQuoted(handler->getQuoteChar(), slice);
}
+ /// Given a command line arg slice, if it is quoted, unquotes it, else returns the slice as is.
+ static UnownedStringSlice maybeUnquoteCommandLineArg(UnownedStringSlice slice);
+
/// If quoting is needed appends to out quoted
static SlangResult appendMaybeQuoted(
Handler* handler,