TemplateConverter::parseOptionsString PHP Method

parseOptionsString() private method

Parses the options string and returns an array of words.
private parseOptionsString ( string $p_optionsString ) : array
$p_optionsString string
return array
    private function parseOptionsString($p_optionsString)
    {
        if (empty($p_optionsString)) {
            return array();
        }
        $words = array();
        $escaped = false;
        $lastWord = '';
        $quotedString = '';
        $isOpenQuote = false;
        foreach (str_split($p_optionsString) as $char) {
            if ($char == '"' && !$isOpenQuote) {
                $isOpenQuote = true;
                $quotedString .= $char;
            } elseif (strlen($quotedString) > 0) {
                $quotedString .= $char;
                if ($char == '"') {
                    $words[] = trim(trim($quotedString, '"'));
                    $quotedString = '';
                    $isOpenQuote = false;
                }
            } else {
                if (preg_match('/[\\s]/', $char) && !$escaped) {
                    if (!empty($lastWord)) {
                        $words[] = $lastWord;
                        $lastWord = '';
                    }
                } elseif ($char == "\\" && !$escaped) {
                    $escaped = true;
                } else {
                    $lastWord .= $char;
                    $escaped = false;
                }
            }
        }
        if (strlen($lastWord) > 0) {
            $words[] = $lastWord;
        }
        return $words;
    }