Latte\TokenIterator::scan PHP Method

scan() protected method

Looks for (first) (not) wanted tokens.
protected scan ( $wanted, $onlyFirst, $advance, $strings = FALSE, $until = FALSE, $prev = FALSE ) : mixed
return mixed
    protected function scan($wanted, $onlyFirst, $advance, $strings = FALSE, $until = FALSE, $prev = FALSE)
    {
        $res = $onlyFirst ? NULL : ($strings ? '' : []);
        $pos = $this->position + ($prev ? -1 : 1);
        do {
            if (!isset($this->tokens[$pos])) {
                if (!$wanted && $advance && !$prev && $pos <= count($this->tokens)) {
                    $this->next();
                }
                return $res;
            }
            $token = $this->tokens[$pos];
            $type = isset($token[Tokenizer::TYPE]) ? $token[Tokenizer::TYPE] : NULL;
            if (!$wanted || (in_array($token[Tokenizer::VALUE], $wanted, TRUE) || in_array($type, $wanted, TRUE)) ^ $until) {
                while ($advance && !$prev && $pos > $this->position) {
                    $this->next();
                }
                if ($onlyFirst) {
                    return $strings ? $token[Tokenizer::VALUE] : $token;
                } elseif ($strings) {
                    $res .= $token[Tokenizer::VALUE];
                } else {
                    $res[] = $token;
                }
            } elseif ($until || !in_array($type, $this->ignored, TRUE)) {
                return $res;
            }
            $pos += $prev ? -1 : 1;
        } while (TRUE);
    }