1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22/**
23 * A parser for reference macros like \0-\9.
24 */
25class CReplacementParser extends CParser {
26
27	/**
28	 * @param string    $source
29	 * @param int       $pos
30	 *
31	 * @return int
32	 */
33	public function parse($source, $pos = 0) {
34		$this->length = 0;
35		$this->match = '';
36
37		$p = $pos;
38
39		if (!isset($source[$p]) || $source[$p] !== '\\') {
40			return CParser::PARSE_FAIL;
41		}
42		$p++;
43
44		if (!isset($source[$p]) || !ctype_digit($source[$p])) {
45			return CParser::PARSE_FAIL;
46		}
47		$p++;
48
49		$this->length = $p - $pos;
50		$this->match = substr($source, $pos, $this->length);
51
52		return (isset($source[$pos + $this->length]) ? self::PARSE_SUCCESS_CONT : self::PARSE_SUCCESS);
53	}
54}
55