Parse a GNU-style option string.

@param string $string the option string
@return Option[]
@throws \InvalidArgumentException
2717
public function parseString($string)
    {
        if (!mb_strlen($string)) {
            throw new \InvalidArgumentException('Option string must not be empty');
        }
        $options = array();
        $eol = mb_strlen($string) - 1;
        $nextCanBeColon = false;
        for ($i = 0; $i <= $eol; ++$i) {
            $ch = $string[$i];
            if (!preg_match('/^[A-Za-z0-9]$/', $ch)) {
                $colon = $nextCanBeColon ? " or ':'" : '';
                throw new \InvalidArgumentException("Option string is not well formed: "
                    ."expected a letter$colon, found '$ch' at position ".($i + 1));
            }
            if ($i == $eol || $string[$i + 1] != ':') {
                $options[] = new Option($ch, null, Getopt::NO_ARGUMENT);
                $nextCanBeColon = true;
            } elseif ($i < $eol - 1 && $string[$i + 2] == ':') {
                $options[] = new Option($ch, null, Getopt::OPTIONAL_ARGUMENT);
                $i += 2;
                $nextCanBeColon = false;
            } else {
                $options[] = new Option($ch, null, Getopt::REQUIRED_ARGUMENT);
                ++$i;
                $nextCanBeColon = true;
            }
        }
        return $options;
    }
1182100
public function stringPermutations(string $string): array {
        $result = [];
        $strLen = \strlen($string);
        if (0 === $strLen) {
            return $result;
        }
        if (1 === $string) {
            $result[] = $string;
            return $result;
        }
        $array = StringUtil::stringToArray($string);

        $result = $this->permute($array, "", $result);
        return $result;
    }
784812
public function parseUrl($string)
    {
        $this->url = [];

        $url = parse_url($string);
        if (!$url || !isset($url['scheme'])) {
            throw new \Exception(sprintf('The url \'%s\' could not be parsed', $string));
        }

        $this->parseUrlArray($url);
    }
1194754
public function fromString($string)
        {
            if (empty($string)) {
                return array();
            }
            $this->directory = null;

            set_error_handler(
                function ($error, $message = '', $file = '', $line = 0) {
                    throw new Exception(sprintf(
                        'Error reading INI string: %s',
                        $message
                    ), $error);
                }, E_WARNING
            );
            $ini = parse_ini_string($string, true);
            restore_error_handler();

            return $this->process($ini);
        }
198812
public static function parse($string, $className)
    {
        // Sanity check
        if (substr_count($string, '.') !== 2) {
            throw new InvalidArgumentException(
                'part "' . $string . '" can not be parsed into a SemVer'
                . ' major.minor.patch version'
            );
        }

        // Simple explode will do here
        $parts = explode('.', $string);

        // Instantiate
        $versionable = new $className;

        // Sanity check of class type
        if (!($versionable instanceof VersionableVersion)) {
            throw new InvalidArgumentException(
                '"' . $className . '" is not Versionable'
            );
        }

        // Versionable parts
        $versionable
            ->setMajor((int) $parts[0])
            ->setMinor((int) $parts[1])
            ->setPatch((int) $parts[2]);

        return $versionable;
    }
95645
public static function fromString( $string ) {
		$values = [
			'1'     => true,
			'y'     => true,
			'yes'   => true,
			'true'  => true,

			'0'     => false,
			'n'     => false,
			'no'    => false,
			'false' => false,
		];

		foreach ( $values as $value => $boolean ) {
			if ( strtolower( $value ) === strtolower( $string ) ) {
				return $boolean;
			}
		}

		// rely on PHP's string to boolean conversion in all other cases
		return (bool) $string;
	}
353896
private function _parseHADocField($string) {
    $separater = '=';
    $pos = strpos($string, $separater);

    if ($pos !== false) {
      $key = substr($string, 0, $pos);
      $value = substr($string, $pos + 1);
      return array($key, $value);
    } else {
      throw new Exception('The are no key and value in the field.');
    }
  }
292358
public static function validatePascalCase($string)
    {
        if (SetupHelper::getPascalCase($string) === $string) {
            return (string)$string;
        }

        throw new InvalidArgumentException(
            sprintf(
                'Provided string "%1$s" was not in PascalCase.',
                $string
            )
        );
    }
1225258
private function _parseConnectionString($string)
  {
    $res = array();
    if (($string == '') || ($string == 'unix://')) {
      // default connection
      $res['type'] = 'socket';
      $res['host'] = 'unix:///usr/local/cps2/storages/' . str_replace('/', '_', $this->_storageName) . '/storage.sock';
      $res['port'] = 0;
    } else if (strncmp($string, 'http://', 7) == 0) {
      // HTTP connection
      $res['type'] = 'http';
      $res['url'] = $string;
    } else if (strncmp($string, 'unix://', 7) == 0) {
      // Unix socket
      $res['type'] = 'socket';
      $res['host'] = $string;
      $res['port'] = 0;
    } else if (strncmp($string, 'tcp://', 6) == 0 || strncmp($string, 'tcps://', 7) == 0) {
      // TCP socket
      $res['type'] = 'socket';
      $uc = parse_url($string);
      if (!isset($uc['host'])) {
        throw new CPS_Exception(array(array('long_message' => 'Invalid connection string', 'code' => ERROR_CODE_INVALID_CONNECTION_STRING, 'level' => 'REJECTED', 'source' => 'CPS_API')));
      }
      $res['host'] = $uc['host'];
      if (isset($uc['port'])) {
        $res['port'] = $uc['port'];
      } else {
        $res['port'] = 5550;
      }
      if (strncmp($string, 'tcps://', 7) == 0)
        $res['ssl'] = true;
    } else {
      throw new CPS_Exception(array(array('long_message' => 'Invalid connection string', 'code' => ERROR_CODE_INVALID_CONNECTION_STRING, 'level' => 'REJECTED', 'source' => 'CPS_API')));
    }
    return $res;
  }
957762
protected function parseString(/*# string */ $string)/*# : array */
    {
        $regex =
        '~^\s*+
            (?:
                (?:([^#\s=]++) \s*+ = \s*+
                    (?|
                        (([^"\'#\s][^#\n]*?)) |
                        (["\'])((?:\\\2|.)*?)\2
                    )?
                ) |
                (?: (\.|source) \s++ ([^#\n]*) )
            )\s*?(?:[#].*)?
        $~mx';

        if (preg_match_all($regex, $string, $matched, \PREG_SET_ORDER)) {
            return $this->clearPairs($matched);
        } else {
            return [];
        }
    }
124180
public static function parseStyles($string)
    {
        $styles = array();
        if (empty($string)) {
            return $styles;
        }

        $declarations = preg_split('/\s*;\s*/', $string);

        foreach ($declarations as $declaration) {
            $declaration = trim($declaration);
            if ($declaration === '') {
                continue;
            }
            $split             = preg_split('/\s*:\s*/', $declaration);
            $styles[$split[0]] = $split[1];
        }

        return $styles;
    }
693417
protected function _parse_string($string, $single_trim = false)
    {
        if ($single_trim) {
            $string = preg_replace('/^[\"\']/', "", $string);
            $string = preg_replace('/[\"\']$/', "", $string);
        } else {
            $string = trim($string, "'\"");
        }

        $string = str_replace(array("\\\n", '\\"', "\\'"),
            array("", '"', "'"), $string);

        // Convert escaped hex characters into ascii characters (e.g. \A => newline)
        $string = preg_replace_callback("/\\\\([0-9a-fA-F]{0,6})/",
            function ($matches) { return \Dompdf\Helpers::unichr(hexdec($matches[1])); },
            $string);
        return $string;
    }
676982
public function parse($string) {
        if (is_array($string)) {
            $string = implode(' ', $string);
        }

        $args = $this->parseString($string);
        $args = $this->unquoteMatches($args);
        $args = $this->normalizeShortOptions($args);

        return $args;
    }
1201625
public static function fromString($string)
    {
        if (preg_match(self::PATTERN_FROM_STRING, trim($string), $matches)) {
            if (2 === count($matches)) {
                // whole number
                return new self((int) $matches[1]);
            } else {
                // either x y/z or x/y
                if ($matches[2]) {
                    // x y/z
                    $whole = new self((int) $matches[1]);

                    return $whole->add(new self(
                        (int) $matches[2],
                        (int) $matches[3]
                    ));
                }

                // x/y
                return new self((int) $matches[1], (int) $matches[3]);
            }
        }

        throw new InvalidArgumentException(sprintf(
            'Cannot parse "%s"',
            $string
        ));
    }
1305867
public function parse( $string )
	{
		if( !is_string( $string ) )														//  no String given
			throw new InvalidArgumentException( 'Given argument is not a string' );		//  throw Exception

		$this->extendPossibleOptionsWithShortcuts();									//  realize Shortcuts

		$position	= 0;																//  initiate Sign Pointer
		$status		= self::STATUS_START;												//  initiate Status
		$buffer		= "";																//  initiate Argument Buffer
		$option		= "";																//  initiate Option Buffer

		while( isset( $string[$position] ) )											//  loop until End of String
		{
			$sign	= $string[$position];												//  get current Sign
			$position ++;																//  increase Sign Pointer

			switch( $status )															//  handle Sign depending on Status
			{
				case self::STATUS_START:												//  open for all Signs
					$this->onReady( $sign, $status, $buffer, $option );					//  handle Sign
					break;
				case self::STATUS_READ_OPTION_KEY:										//  open for Option Key Signs
					$this->onReadOptionKey( $sign, $status, $buffer, $option );			//  handle Sign
					break;
				case self::STATUS_READ_OPTION_VALUE:									//  open for Option Value Signs
					$this->onReadOptionValue( $sign, $status, $buffer, $option );		//  handle Sign
					break;
				case self::STATUS_READ_ARGUMENT:										//  open for Argument Signs
					$this->onReadArgument( $sign, $status, $buffer );					//  handle Sign
					break;
			}
		}
		$this->onEndOfLine( $status, $buffer, $option );								//  close open States
	}
586736
protected function _parse_string($string, $single_trim = false) {
    if ($single_trim) {
      $string = preg_replace("/^[\"\']/", "", $string);
      $string = preg_replace("/[\"\']$/", "", $string);
    }
    else {
      $string = trim($string, "'\"");
    }
    
    $string = str_replace(array("\\\n",'\\"',"\\'"),
                          array("",'"',"'"), $string);

    // Convert escaped hex characters into ascii characters (e.g. \A => newline)
    $string = preg_replace_callback("/\\\\([0-9a-fA-F]{0,6})(\s)?(?(2)|(?=[^0-9a-fA-F]))/",
                                    create_function('$matches',
                                                    'return chr(hexdec($matches[1]));'),
                                    $string);
    return $string;
  }
1209995
protected function parseArguments(string $string): ArgumentList
    {
        $argParser = $this->argumentParserFactory->create($string);
        return $argParser->tokenise();
    }