/*!
Parse arguments for {while}
968236
function parseWhileFunction( &$args, $tpl, &$text, &$text_len, &$cur_pos,
                                 $relatedTemplateName, $startLine, $startColumn, $rootNamespace )
    {
        $cond = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );
        if ( !count( $cond ) )
        {
            $this->showParseErrorMessage( $tpl, $text, $text_len, $cur_pos, $relatedTemplateName, $startLine, $startColumn,
                                          'while', 'Not enough arguments' );
            return;

        }
        $args['condition'] = $cond;

        // skip whitespaces
        $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );

        if ( $cur_pos == $text_len ) // no more arguments
            return;

        $this->parseSequenceParameter( true, 'while',
                                       $args, $tpl, $text, $text_len, $cur_pos,
                                       $relatedTemplateName, $startLine, $startColumn, $rootNamespace );
    }
103746
protected function parseArguments()
	{
		// Get the list of argument values from the environment.
		$args = $_SERVER['argv'];

		// Set the path used for program execution and remove it form the program arguments.
		$this->executable = array_shift($args);

		// We use a for loop because in some cases we need to look ahead.
		for ($i = 0; $i < count($args); $i++)
		{
			// Get the current argument to analyze.
			$arg = $args[$i];

			// First let's tackle the long argument case.  eg. --foo
			if (strlen($arg) > 2 && substr($arg, 0, 2) == '--')
			{
				// Attempt to split the thing over equals so we can get the key/value pair if an = was used.
				$arg = substr($arg, 2);
				$parts = explode('=', $arg);
				$this->data[$parts[0]] = true;

				// Does not have an =, so let's look ahead to the next argument for the value.
				if (count($parts) == 1 && isset($args[$i + 1]) && preg_match('/^--?.+/', $args[$i + 1]) == 0)
				{
					$this->data[$parts[0]] = $args[$i + 1];

					// Since we used the next argument, increment the counter so we don't use it again.
					$i++;
				}
				elseif (count($parts) == 2)
				// We have an equals sign so take the second "part" of the argument as the value.
				{
					$this->data[$parts[0]] = $parts[1];
				}
			}

			// Next let's see if we are dealing with a "bunch" of short arguments.  eg. -abc
			elseif (strlen($arg) > 2 && $arg[0] == '-')
			{
				// For each of these arguments set the value to TRUE since the flag has been set.
				for ($j = 1; $j < strlen($arg); $j++)
				{
					$this->data[$arg[$j]] = true;
				}
			}

			// OK, so it isn't a long argument or bunch of short ones, so let's look and see if it is a single
			// short argument.  eg. -h
			elseif (strlen($arg) == 2 && $arg[0] == '-')
			{
				// Go ahead and set the value to TRUE and if we find a value later we'll overwrite it.
				$this->data[$arg[1]] = true;

				// Let's look ahead to see if the next argument is a "value".  If it is, use it for this value.
				if (isset($args[$i + 1]) && preg_match('/^--?.+/', $args[$i + 1]) == 0)
				{
					$this->data[$arg[1]] = $args[$i + 1];

					// Since we used the next argument, increment the counter so we don't use it again.
					$i++;
				}
			}

			// Last but not least, we don't have a key/value based argument so just add it to the arguments list.
			else
			{
				$this->args[] = $arg;
			}
		}
	}
1255596
function parseMulti (params, section, stripped) {
  const split = stripped.split('*')
  const value = params[split[0]]

  assert(Array.isArray(value), `The ${stripped} parameter should be an array`)
  assert(parseInt(split[1], 10) === value.length, 'The number of passed multi-parameters does not match the defined multiplier')

  const src = value.join('/')
  assert(src, `The '${stripped} parameter is missing`)

  return { dst: section, src }
}
28203
function iterator(params, cmd, p)
{
  var value = params[p];

  // shortcut
  if (!cmd) return cmd;

  // fold booleans into strings accepted by shell
  if (typeof value == 'boolean')
  {
    value = value ? '1' : '';
  }

  if (value !== null && ['undefined', 'string', 'number'].indexOf(typeof value) == -1)
  {
    // empty out cmd to signal the error
    return '';
  }

  // use empty string for `undefined`
  return cmd.replace(new RegExp('\\$\\{' + p + '\\}', 'g'), (value !== undefined && value !== null) ? value : '');
}
25801
public function _parse($args)
    {
        $this->_values = [];
        $this->_options = [];

        if (in_array(end($args), ['', '-', '--'], true)) {
            array_pop($args);
        }

        while ($args) {
            $o = array_shift($args);
            if ($o[0] !== '-') {
                $this->_values[] = $o;
                continue;
            }

            if (preg_match('#^-((\w)|-([\w-_]+))=(.*)$#', $o, $match)) {
                $this->_options[$match[2]] = $match[4];
                continue;
            }

            if ($o[1] === '-') {
                if (strlen($o) < 3) {
                    throw new ArgumentsException(['long `:option` option is too short', 'option' => $o]);
                }

                $this->_options[substr($o, 2)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            } elseif (strlen($o) > 2) {
                if (!$args || $args[0][0] === '-') {
                    /** @noinspection PhpParamsInspection */
                    foreach (str_split(substr($o, 1), 1) as $c) {
                        $this->_options[$c] = 1;
                    }
                } else {
                    $this->_options[substr($o, 1)] = array_shift($args);
                }
            } else {
                $this->_options[substr($o, 1)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            }
        }

        return $this;
    }
862981
function parse()
    {
        //The amount of opening braces is compared to the amount of closing braces
        //Braces inside comments are ignored
        $this->warnings = array();
        $this->data = array();
        $valid = true;
        $open = 0;
        $entry = false;
        $char = '';
        $lastchar = '';
        $buffer = '';
        for ($i = 0; $i < strlen($this->content); $i++) {
            $char = substr($this->content, $i, 1);
            if ((0 != $open) && ('@' == $char)) {
                if (!$this->_checkAt($buffer)) {
                    $this->_generateWarning('WARNING_MISSING_END_BRACE', '', $buffer);
                    //To correct the data we need to insert a closing brace
                    $char = '}';
                    $i--;
                }
            }
            if ((0 == $open) && ('@' == $char)) { //The beginning of an entry
                $entry = true;
            } elseif ($entry && ('{' == $char) && ('\\' != $lastchar)) { //Inside an entry and non quoted brace is opening
                $open++;
            } elseif ($entry && ('}' == $char) && ('\\' != $lastchar)) { //Inside an entry and non quoted brace is closing
                $open--;
                if ($open < 0) { //More are closed than opened
                    $valid = false;
                }
                if (0 == $open) { //End of entry
                    $entry = false;
                    $entrydata = $this->_parseEntry($buffer);
                    if (!$entrydata) {
                        /**
                         * This is not yet used.
                         * We are here if the Entry is either not correct or not supported.
                         * But this should already generate a warning.
                         * Therefore it should not be necessary to do anything here
                         */
                    } else {
                        $this->data[] = $entrydata;
                    }
                    $buffer = '';
                }
            }
            if ($entry) { //Inside entry
                $buffer .= $char;
            }
            $lastchar = $char;
        }
        //If open is one it may be possible that the last ending brace is missing
        if (1 == $open) {
            $entrydata = $this->_parseEntry($buffer);
            if (!$entrydata) {
                $valid = false;
            } else {
                $this->data[] = $entrydata;
                $buffer = '';
                $open = 0;
            }
        }
        //At this point the open should be zero
        if (0 != $open) {
            $valid = false;
        }
        //Are there Multiple entries with the same cite?
        if ($this->_options['validate']) {
            $cites = array();
            foreach ($this->data as $entry) {
                $cites[] = $entry['cite'];
            }
            $unique = array_unique($cites);
            if (sizeof($cites) != sizeof($unique)) { //Some values have not been unique!
                $notuniques = array();
                for ($i = 0; $i < sizeof($cites); $i++) {
                    if (empty($unique[$i])) {
                        $notuniques[] = $cites[$i];
                    }
                }
                $this->_generateWarning('WARNING_MULTIPLE_ENTRIES', implode(',', $notuniques));
            }
        }
        if ($valid) {
            $this->content = '';
            return true;
        } else {
            throw new BibtexException('Unbalanced parenthesis');
        }
    }
220438
function collectArguments(args) {
  for (var i = 0; i < args.length; i += 2) {
    if (args[i].lastIndexOf('--', 0) !== 0) {
      --i;
      continue;
    }

    flags[args[i]] = args[i + 1];
  }
}
1012657
function parseStringNumbers (parser) {
  const length = parser.buffer.length - 1
  var offset = parser.offset
  var number = 0
  var res = ''

  if (parser.buffer[offset] === 45) {
    res += '-'
    offset++
  }

  while (offset < length) {
    var c1 = parser.buffer[offset++]
    if (c1 === 13) { // \r\n
      parser.offset = offset + 1
      if (number !== 0) {
        res += number
      }
      return res
    } else if (number > 429496728) {
      res += (number * 10) + (c1 - 48)
      number = 0
    } else if (c1 === 48 && number === 0) {
      res += 0
    } else {
      number = (number * 10) + (c1 - 48)
    }
  }
}
1290325
function parse($args = null)
    {
        if ($args === null) {
            $args = array_slice($_SERVER['argv'], 1);
        }

        foreach ($args as $pos => $arg) {
            // reset value
            $value = null;

            if (substr($arg, 0, 1) === '-') {
                if (preg_match('/^(.+)=(.+)$/', $arg, $matches)) {
                    $arg = $matches[1];
                    $value = $matches[2];
                }

                if (!$flag = @$this->flags[$arg]) {
                    throw new ParseException(sprintf('Flag "%s" is not defined.', $arg));
                }

                unset($args[$pos]);

                if ($flag->hasValue) {
                    if (!isset($value)) {
                        $value = $args[$pos + 1];
                        unset($args[$pos + 1]);
                    }
                } else {
                    $value = true;
                }

                if (null !== $flag->callback) {
                    call_user_func_array($flag->callback, array(&$value));
                }

                # Set the reference given as the flag's 'var'.
                $flag->var = $this->parsedFlags[$flag->name] = $value;
            }
        }

        # TODO: Refactor this so this fits into the above foreach
        foreach ($this->flags as $flag) {
            if (!array_key_exists($flag->name, $this->parsedFlags)) {
                $flag->var = $this->parsedFlags[$flag->name] = $flag->defaultValue;
            }
        }

        $this->parsedArgs = $args = array_values($args);

        $pos = 0;

        foreach ($this->args as $arg) {
            if ($arg->required and !isset($args[$pos])) {
                throw new ArgumentException(sprintf(
                    'Missing required argument "%s"', $arg->name
                ));
            }

            if (isset($args[$pos])) {
                if ($arg->vararg) {
                    $value = array_slice($args, $pos);
                    $pos += count($value);
                } else {
                    $value = $args[$pos];
                    $pos++;
                }
            } else {
                $value = $arg->defaultValue;
            }

            $this->parsedNamedArgs[$arg->name] = $value;
        }
    }
467930
public function parse($arguments)
    {
        if (!is_array($arguments)) {
            $arguments = explode(' ', $arguments);
        }
        $operands = array();
        $numArgs = count($arguments);
        for ($i = 0; $i < $numArgs; ++$i) {
            $arg = trim($arguments[$i]);
            if (empty($arg)) {
                continue;
            }
            if (($arg === '--') || ($arg === '-') || (mb_substr($arg, 0, 1) !== '-')){
                // no more options, treat the remaining arguments as operands
                $firstOperandIndex = ($arg == '--') ? $i + 1 : $i;
                $operands = array_slice($arguments, $firstOperandIndex);
                break;
            }
            if (mb_substr($arg, 0, 2) == '--') {
                $this->addLongOption($arguments, $i);
            } else {
                $this->addShortOption($arguments, $i);
            }
        } // endfor

        $this->addDefaultValues();

        // remove '--' from operands array
        foreach ($operands as $operand) {
            if ($operand !== '--') {
                $this->operands[] = $operand;
            }
        }
    }
1182918
function ( obj, arg ) {
		arg = arg || ",";

		return string.trim( obj ).split( new RegExp( "\\s*" + arg + "\\s*" ) );
	}
1016499
def parse_args(string):
    
    import ast
    is_quoted = False
    result_parts = []
    current_str = ""
    while len(string) > 0:
        if string[0] == "\"":
            is_quoted = not is_quoted
            current_str += string[0]
        elif string[0].isspace():
            if is_quoted:
                current_str += string[0]
            else:
                result_parts.append(current_str)
                current_str = ""
            # end if
        else:
            current_str += string[0]
        # end if
        string = string[1:]
    # end while
    if current_str:  # last part of the array
        result_parts.append(current_str)
    # end if
    for i in range(len(result_parts)):
        # Will try for each element if it is something pythonic. Parsed type will replace original list element.
        try:
            part = ast.literal_eval(result_parts[i])
            result_parts[i] = part  # write it back.
        except ValueError:
            # could not parse -> is string
            pass  # because already is str.
        # end try
    # end for
    return result_parts
775726
function parseArguments$3(args) {
        var first = args[0];
        var second = args[1];

        return typeof first === 'string' ? { namespace: first, mappings: second } : { namespace: null, mappings: first };
    }
675215
function parse(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $prg = \preg_match('/(?:<@!?)?(\d{15,})>?/', $value, $matches);
        if($prg === 1) {
            return $this->client->users->get($matches[1]);
        }
        
        $search = \mb_strtolower($value);
        
        $inexactUsers = $this->client->users->filter(function ($user) use ($search) {
            return (\mb_stripos($user->tag, $search) !== false);
        });
        $inexactLength = $inexactUsers->count();
        
        if($inexactLength === 0) {
             return null;
        }
        if($inexactLength === 1) {
            return $inexactUsers->first();
        }
        
        $exactUsers = $this->client->users->filter(function ($user) use ($search) {
            return (\mb_strtolower($user->tag) === $search);
        });
        $exactLength = $exactUsers->count();
        
        if($exactLength === 1) {
            return $exactUsers->first();
        }
        
        return null;
    }
867047
function parseForeachFunction( &$args, $tpl, &$text, &$text_len, &$cur_pos,
                                   $relatedTemplateName, $startLine, $startColumn, $rootNamespace )
    {
        // parse array
        $args['array'] = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );

        // skip whitespaces
        $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );

        // parse 'as' keyword
        $asEndPos = $this->ElementParser->identifierEndPosition( $tpl, $text, $cur_pos, $text_len );
        $word = substr( $text, $cur_pos, $asEndPos-$cur_pos );
        if ( $word != 'as' )
        {
            $this->showParseErrorMessage( $tpl, $text, $text_len, $cur_pos, $relatedTemplateName, $startLine, $startColumn,
                                          'foreach', "Expected keyword 'as' not found" );
            return;
        }
        $cur_pos = $asEndPos;

        // skip whitespaces
        $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );

        // parse variable name
        $var1 = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );

        $nextTokenPos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );

        // parse itemVar (if specified)
        if ( $nextTokenPos <= ( $text_len-2 ) && $text[$nextTokenPos] == '=' && $text[$nextTokenPos+1] == '>' )
        {
            // skip whitespaces
            $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $nextTokenPos+2, $text_len );

            $args['key_var']  = $var1;

            // parse item variable name
            $args['item_var'] = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );
        }
        else
            $args['item_var'] = $var1;

        /*
         * parse optional parameters
         */

        while ( $cur_pos < $text_len )
        {
            // skip whitespaces
            $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );

            $paramNameEndPos = $this->ElementParser->identifierEndPosition( $tpl, $text, $cur_pos, $text_len );
            $paramName = substr( $text, $cur_pos, $paramNameEndPos-$cur_pos );
            $cur_pos = $paramNameEndPos;

            if ( $paramName == 'sequence' )
            {
                if ( ! $this->parseSequenceParameter( false, 'foreach',
                                               $args, $tpl, $text, $text_len, $cur_pos, $relatedTemplateName, $startLine, $startColumn, $rootNamespace ) )
                    return;
            }
            elseif ( $paramName == 'offset' )
            {
                $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );
                $args['offset'] = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );
            }
            elseif ( $paramName == 'max' )
            {
                $cur_pos = $this->ElementParser->whitespaceEndPos( $tpl, $text, $cur_pos, $text_len );
                $args['max'] = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $text, $cur_pos, $cur_pos, $text_len, $rootNamespace );
            }
            elseif ( $paramName == 'reverse' )
            {
                $reverseValText = '1';
                $args['reverse'] = $this->ElementParser->parseVariableTag( $tpl, $relatedTemplateName, $reverseValText, 0, $reverseValPos, 1, $rootNamespace );
            }
            else
            {
                $this->showParseErrorMessage( $tpl, $text, $text_len, $cur_pos, $relatedTemplateName, $startLine, $startColumn,
                                              'foreach', "Unknown parameter '$paramName'" );
                return;
            }
        }
    }
1057954
static function parseArgs(string $argString, $argCount = null, bool $allowSingleQuotes = true) {
        if(\mb_strlen($argString) === 0) {
            return array();
        }
        
        if($argCount === 1) {
            return array($argString);
        }
        
        $regex = '/(?:(['.($allowSingleQuotes ? "'" : '').'"])(.*?)(?<!\\\\)(?>\\\\\\\)*\1|([^\\s]+))/Su';
        $results = array();
        
        $argString = \trim($argString);
        
        if($argCount === null) {
            $argCount = \mb_strlen($argString); // Large enough to get all items
        }
        
        $content = $argString;
        \preg_match_all($regex, $argString, $matches);
        
        foreach($matches[0] as $key => $val) {
            $argCount--;
            if($argCount === 0) {
                break;
            }
            
            $val = \trim(($matches[3][$key] !== '' ? $matches[3][$key] : ($matches[2][$key] !== '' ? $matches[2][$key] : $matches[1][$key])));
            $results[] = $val;
            
            $content = \trim(\preg_replace('/'.\preg_quote($val, '/').'/u', '', $content, 1));
        }
        
        // If text remains, push it to the array as-is (except for wrapping quotes, which are removed)
        if(\mb_strlen($content) > 0) {
            $results[] = \preg_replace(($allowSingleQuotes ? '/^("|\')(.*)\1$/u' : '/^(")(.*)\1$/u'), '$2', $content);
        }
        
        if(\count($results) > 0) {
            $results = \array_filter($results, function ($val) {
                return (\mb_strlen(\trim($val)) > 0);
            });
        }
        
        return $results;
    }
425750
function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
    {
        $params = $functionParameters;
        $loop = null;
        if ( isset( $params["loop"] ) )
        {
            $loop = $tpl->elementValue( $params["loop"], $rootNamespace, $currentNamespace, $functionPlacement );
        }
        if ( $loop !== null and !is_array( $loop ) )
        {
            $tpl->error( $functionName, "Can only loop arrays", $functionPlacement );
            return;
        }

        $name = "";
        if ( !isset( $params["name"] ) )
        {
            $tpl->missingParameter( $functionName, "name" );
            return;
        }
        $name = $tpl->elementValue( $params["name"], $rootNamespace, $currentNamespace, $functionPlacement );
        $seq_var =& $GLOBALS["eZTemplateSequence-$name"];
        if ( !is_array( $seq_var ) )
            $seq_var = array();
        if ( $loop !== null )
        {
            $seq_var["loop"] = $loop;
            $seq_var["iteration"] = 0;
            $seq_var["index"] = 0;
        }
        else
        {
            $index =& $seq_var["index"];
            $iteration =& $seq_var["iteration"];
            ++$iteration;
            ++$index;
            if ( $index >= count( $seq_var["loop"] ) )
                $index = 0 ;
        }
        $tpl->setVariable( "item", $seq_var["loop"][$seq_var["index"]], $tpl->mergeNamespace( $rootNamespace, $name ) );
        $tpl->setVariable( "iteration", $seq_var["iteration"], $tpl->mergeNamespace( $rootNamespace, $name ) );
    }