Scan a string for tokens using the same engine.

@param $string

@return array a unique list of all the raw mustache tags found in the string
8305
public function getTokens($string)
    {
        $tokens      = [];
        $scanResults = $this->engine->getTokenizer()->scan($string);

        foreach ($scanResults as $scanResult) {
            if (
                isset($scanResult['type'])
                && isset($scanResult['name'])
                && \Mustache_Tokenizer::T_ESCAPED === $scanResult['type']
            ) {
                $tokens[$scanResult['name']] = true;
            }
        }

        return array_keys($tokens);
    }
610276
public function parseTokens($string)
    {
        $this->string = $string;
        $this->cursor = 0;
        $this->current = isset($this->string[0]) ? $this->string[0] : null;
        $this->next = isset($this->string[1]) ? $this->string[1] : null;

        // Unify result of ctype_space() across systems
        $previousLocale = setlocale(LC_CTYPE, 0);
        setlocale(LC_CTYPE, 'C');
        $tokens = $this->doParseTokens();
        setlocale(LC_CTYPE, $previousLocale);

        return $tokens;
    }
1176130
public function parseString($string)
    {
        $tokens = new Stack($this->tokenizer->tokenize($string));

        if ($tokens[0]->type === Tokenizer::T_EOF) {
            return new CTX\AccountInfoList();
        }

        $ctx = new CTX();
        $this->reduceStruct($tokens, $ctx);

        return $ctx->accountInfoList[0];
    }
478898
public static function getStringElements($string, $separator)
    {
        $matches = [];
        $pattern = sprintf('|[^\%s]+|', $separator);
        $matchCount = preg_match_all($pattern, $string, $matches);

        if ($matchCount > 1) {
            return $matches[0];
        }

        return [];
    }
729442
public static function tags(string $string): string
    {
        $string = str_replace('<', '&lt;', $string);
        $string = str_replace('>', '&gt;', $string);
        return $string;
    }
491027
public static function get_string_from_input($string) {
        $string = trim($string);

        if (preg_match('|^([a-zA-Z][a-zA-Z0-9\.:/_-]*),([a-zA-Z][a-zA-Z0-9\.:/_-]*)$|', $string, $matches)) {
            if ($matches[2] === 'moodle') {
                $matches[2] = 'core';
            }

            if (get_string_manager()->string_exists($matches[1], $matches[2])) {
                $string = get_string($matches[1], $matches[2]);
            }
        }

        return $string;
    }
386486
public function compare($string)
    {
        foreach ($this->tokens as $token) {
            if (strcasecmp($token, $string) === 0) {
                $this->found = true;
            }
        }
    }
100254
private function separateSelectString(string $string)
    {
        if (false === strpos($string, '(')) {
            return array_map('trim', explode(',', $string));
        }

        $opened = $closed = 0;
        $cnt = mb_strlen($string);
        $arrayStrings = [];
        $substring = '';

        for ($i = 0; $i < $cnt; $i++) {
            $substring .= $string[$i];
            if ('(' === $string[$i]) {
                $opened++;
            } elseif (')' === $string[$i]) {
                $closed++;
            } elseif (',' === $string[$i] && $opened === $closed) {
                $arrayStrings[] = trim($substring);
            }
        }
        $arrayStrings[] = trim($substring);

        return $arrayStrings;
    }
979595
protected function getEncodableWordTokens($string)
    {
        $tokens = [];

        $encodedToken = '';
        // Split at all whitespace boundaries
        foreach (preg_split('~(?=[\t ])~', $string) as $token) {
            if ($this->tokenNeedsEncoding($token)) {
                $encodedToken .= $token;
            } else {
                if (strlen($encodedToken) > 0) {
                    $tokens[] = $encodedToken;
                    $encodedToken = '';
                }
                $tokens[] = $token;
            }
        }
        if (strlen($encodedToken)) {
            $tokens[] = $encodedToken;
        }

        return $tokens;
    }
106211
private function parseSquash(string $string) : array
    {
        // As always, regexes to the rescue
        $matches = [];
        // @todo find out why using /^...$/ does not work capturing all groups
        if (!preg_match_all('/((\(\w+(?:\s+\w+)+\)\s*)+?)/ui', trim($string), $matches)) {
            throw new \InvalidArgumentException();
        }

        $ret = [];

        foreach ($matches[1] as $group) {
            $ret[] = array_filter(preg_split('/[\(\)\s]+/', $group));
        }

        return $ret;
    }
386503
private function scanNextType($string)
    {
        foreach ($this->patterns as $type => $pattern) {
            if (preg_match('/^(' . $pattern . ')/sS', $string, $matches) === 1) {
                return [
                    'type'   => $type,
                    'match'  => $matches[1],
                    'length' => strlen($matches[1]),
                ];
            }
        }

        return null;
    }
969793
public function findCacheByString(string $string)
    {

        // Check if already in cache
        if (!$this->isCachedByString($string)) {
            return null;
        }

        return $this->cacheByString[$string];
    }
282435
protected function parseDocument( $string )
    {
        $document = array();

        // Read document headers
        while ( preg_match( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm', $string, $match ) )
        {
            $document[$match['header']] = trim( $match['value'] );
            $string = substr( $string, strlen( $match[0] ) + 1 );
        }

        if ( strpos( $document['Content-Type'], 'multipart/mixed' ) === 0 )
        {
            // Rebuild full document
            $body = fopen( 'string://', 'w' );
            foreach ( $document as $key => $value )
            {
                fwrite( $body, "$key: $value\r\n" );
            }
            fwrite( $body, $string );
            fseek( $body, 0 );

            $document['body'] = array();
            $parser = new phpillowToolMultipartParser( $body );
            while ( ( $part = $parser->getDocument() ) !== false )
            {
                $document['body'][] = $part;
            }
        }
        else
        {
            $document['body'] = trim( $string );
        }

        return $document;
    }
908191
public static function matchSemVer($string)
    {
        // Array of matches for PCRE
        $matches = array();

        // Match the possible parts of a SemVer
        $matched = preg_match(
            self::$version,
            $string,
            $matches
        );

        // No match, invalid
        if (!$matched) {
            throw new InvalidArgumentException(
                '"' . $string . '" is not a valid SemVer'
            );
        }

        // Return matched array
        return $matches;
    }
82054
public function readString($string)
    {
        if (!is_string($string))
            throw new IniReadingException('The expected type is string');

        // PHP 5.3.3, an empty line return is needed at the end.
        $string .= "\n";

        $data = @parse_ini_string($string, true);
        if ($data === false) {
            $e = error_get_last();
            throw new IniReadingException('Syntax error in INI configuration: ' . $e['message']);
        }

        $rawValues = @parse_ini_string($string, true, INI_SCANNER_RAW);

        return $this->toCollection($this->decode($data, $rawValues));
    }
631899
protected function _parseAttributes($string)
    {
        $result = array();

        if (!empty($string)) {
            $attr   = array();

            preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);

            if (is_array($attr)) {
                $numPairs = count($attr[1]);
                for ($i = 0; $i < $numPairs; $i++) {
                    $result[$attr[1][$i]] = $attr[2][$i];
                }
            }
        }

        return $result;
    }
239477
protected function processOneToken($string)
    {
        $token = $this->getToken($string, $this->currentStringLength, $this->previousToken);
        $this->tokens[] = $token;
        $this->tokenLength = \strlen($token[self::TOKEN_VALUE]);
        $this->previousToken = $token;

        $this->oldStringLength = $this->currentStringLength;
        $this->currentStringLength -= $this->tokenLength;

        return \substr($string, $this->tokenLength);
    }