Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / node_modules / yargs / lib / tokenize-arg-string.js
diff --git a/legacy-libs/grpc/node_modules/yargs/lib/tokenize-arg-string.js b/legacy-libs/grpc/node_modules/yargs/lib/tokenize-arg-string.js
new file mode 100644 (file)
index 0000000..df43fa5
--- /dev/null
@@ -0,0 +1,32 @@
+// take an un-split argv string and tokenize it.
+module.exports = function (argString) {
+  var i = 0
+  var c = null
+  var opening = null
+  var args = []
+
+  for (var ii = 0; ii < argString.length; ii++) {
+    c = argString.charAt(ii)
+
+    // split on spaces unless we're in quotes.
+    if (c === ' ' && !opening) {
+      i++
+      continue
+    }
+
+    // don't split the string if we're in matching
+    // opening or closing single and double quotes.
+    if (c === opening) {
+      opening = null
+      continue
+    } else if ((c === "'" || c === '"') && !opening) {
+      opening = c
+      continue
+    }
+
+    if (!args[i]) args[i] = ''
+    args[i] += c
+  }
+
+  return args
+}