"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/yargs/lib/tokenize-arg-string.js" (11 Apr 2017, 674 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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