pQuery\TokenizerBase::next_pos PHP Метод

next_pos() публичный Метод

Finds the next token by searching for a string
public next_pos ( string $needle, boolean $callback = true ) : integer
$needle string The needle that's being searched for
$callback boolean Should the function check the charmap after finding the needle?
Результат integer Next token ({@link TOK_NULL} if none)
    function next_pos($needle, $callback = true)
    {
        $this->token_start = $this->pos;
        if ($this->pos < $this->size && ($p = stripos($this->doc, $needle, $this->pos + 1)) !== false) {
            $len = $p - $this->pos - 1;
            if ($len > 0) {
                $str = substr($this->doc, $this->pos + 1, $len);
                if (($l = strrpos($str, "\n")) !== false) {
                    ++$this->line_pos[0];
                    $this->line_pos[1] = $l + $this->pos + 1;
                    $len -= $l;
                    if ($len > 0) {
                        $str = substr($str, 0, -$len);
                        $this->line_pos[0] += substr_count($str, "\n");
                    }
                }
            }
            $this->pos = $p;
            if ($callback && isset($this->char_map[$this->doc[$this->pos]])) {
                if (is_string($this->char_map[$this->doc[$this->pos]])) {
                    return $this->token = $this->{$this->char_map[$this->doc[$this->pos]]}();
                } else {
                    return $this->token = $this->char_map[$this->doc[$this->pos]];
                }
            } else {
                return $this->token = self::TOK_UNKNOWN;
            }
        } else {
            $this->pos = $this->size;
            return $this->token = self::TOK_NULL;
        }
    }