Initial commit
[yaffs-website] / node_modules / yargs-parser / lib / tokenize-arg-string.js
1 // take an un-split argv string and tokenize it.
2 module.exports = function (argString) {
3   if (Array.isArray(argString)) return argString
4
5   var i = 0
6   var c = null
7   var opening = null
8   var args = []
9
10   for (var ii = 0; ii < argString.length; ii++) {
11     c = argString.charAt(ii)
12
13     // split on spaces unless we're in quotes.
14     if (c === ' ' && !opening) {
15       i++
16       continue
17     }
18
19     // don't split the string if we're in matching
20     // opening or closing single and double quotes.
21     if (c === opening) {
22       opening = null
23       continue
24     } else if ((c === "'" || c === '"') && !opening) {
25       opening = c
26       continue
27     }
28
29     if (!args[i]) args[i] = ''
30     args[i] += c
31   }
32
33   return args
34 }