src/Ulrichsg/Getopt/OptionParser.php
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;
    }
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;
    }
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 ; }
Parse a GNU-style option string.

@param string $string the option string
@return Option[]
@throws \InvalidArgumentException
Parse a GNU - style option string .