* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace RectorPrefix20210905\Symfony\Component\Console\Input; use RectorPrefix20210905\Symfony\Component\Console\Exception\InvalidArgumentException; /** * StringInput represents an input provided as a string. * * Usage: * * $input = new StringInput('foo --bar="foobar"'); * * @author Fabien Potencier */ class StringInput extends \RectorPrefix20210905\Symfony\Component\Console\Input\ArgvInput { public const REGEX_STRING = '([^\\s]+?)(?:\\s|(?setTokens($this->tokenize($input)); } /** * Tokenizes a string. * * @throws InvalidArgumentException When unable to parse input (should never happen) */ private function tokenize(string $input) : array { $tokens = []; $length = \strlen($input); $cursor = 0; while ($cursor < $length) { if (\preg_match('/\\s+/A', $input, $match, 0, $cursor)) { } elseif (\preg_match('/([^="\'\\s]+?)(=?)(' . self::REGEX_QUOTED_STRING . '+)/A', $input, $match, 0, $cursor)) { $tokens[] = $match[1] . $match[2] . \stripcslashes(\str_replace(['"\'', '\'"', '\'\'', '""'], '', \substr($match[3], 1, -1))); } elseif (\preg_match('/' . self::REGEX_QUOTED_STRING . '/A', $input, $match, 0, $cursor)) { $tokens[] = \stripcslashes(\substr($match[0], 1, -1)); } elseif (\preg_match('/' . self::REGEX_STRING . '/A', $input, $match, 0, $cursor)) { $tokens[] = \stripcslashes($match[1]); } else { // should never happen throw new \RectorPrefix20210905\Symfony\Component\Console\Exception\InvalidArgumentException(\sprintf('Unable to parse input near "... %s ...".', \substr($input, $cursor, 10))); } $cursor += \strlen($match[0]); } return $tokens; } }