MediaWiki
REL1_37
HeaderParserBase.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest\HeaderParser
;
4
8
class
HeaderParserBase
{
12
protected
$input
;
13
17
protected
$pos
;
18
22
protected
$inputLength
;
23
29
protected
function
setInput
(
$input
) {
30
$this->input =
$input
;
31
$this->pos = 0;
32
$this->inputLength = strlen(
$input
);
33
}
34
41
protected
function
consumeString
(
$s
) {
42
if
( $this->pos >= $this->inputLength ) {
43
$this->
error
(
"Expected \"$s\" but got end of string"
);
44
}
45
if
( substr_compare( $this->input,
$s
, $this->pos, strlen(
$s
) ) === 0 ) {
46
$this->pos += strlen(
$s
);
47
}
else
{
48
$this->
error
(
"Expected \"$s\""
);
49
}
50
}
51
55
protected
function
skipWhitespace
() {
56
$this->pos += strspn( $this->input,
" \t"
, $this->pos );
57
}
58
66
protected
function
error
( $message ) {
67
throw
new
HeaderParserError
(
"$message at {$this->pos}"
);
68
}
69
77
protected
function
consumeFixedDigits
( $numDigits ) {
78
$digits = substr( $this->input, $this->pos, $numDigits );
79
if
( strlen( $digits ) !== $numDigits || !preg_match(
'/^[0-9]*$/'
, $digits ) ) {
80
$this->
error
(
"expected $numDigits digits"
);
81
}
82
$this->pos += $numDigits;
83
return
$digits;
84
}
85
92
protected
function
assertEnd
() {
93
if
( $this->pos !== $this->inputLength ) {
94
$this->
error
(
"trailing characters"
);
95
}
96
}
97
}
MediaWiki\Rest\HeaderParser\HeaderParserBase
Definition
HeaderParserBase.php:8
MediaWiki\Rest\HeaderParser\HeaderParserBase\$input
string $input
The input string being processed.
Definition
HeaderParserBase.php:12
MediaWiki\Rest\HeaderParser\HeaderParserBase\setInput
setInput( $input)
Set the input, and derived convenience properties.
Definition
HeaderParserBase.php:29
MediaWiki\Rest\HeaderParser\HeaderParserBase\assertEnd
assertEnd()
If the position is not at the end of the input string, raise an error, complaining of trailing charac...
Definition
HeaderParserBase.php:92
MediaWiki\Rest\HeaderParser\HeaderParserBase\$inputLength
int $inputLength
The length of $input.
Definition
HeaderParserBase.php:22
MediaWiki\Rest\HeaderParser\HeaderParserBase\$pos
int $pos
The position within $input.
Definition
HeaderParserBase.php:17
MediaWiki\Rest\HeaderParser\HeaderParserBase\consumeFixedDigits
consumeFixedDigits( $numDigits)
Consume a specified number of digits, or throw an exception.
Definition
HeaderParserBase.php:77
MediaWiki\Rest\HeaderParser\HeaderParserBase\consumeString
consumeString( $s)
Consume a specified string, or throw an exception.
Definition
HeaderParserBase.php:41
MediaWiki\Rest\HeaderParser\HeaderParserBase\skipWhitespace
skipWhitespace()
Skip whitespace at the input position (OWS)
Definition
HeaderParserBase.php:55
MediaWiki\Rest\HeaderParser\HeaderParserBase\error
error( $message)
Throw an exception to indicate a parse error.
Definition
HeaderParserBase.php:66
MediaWiki\Rest\HeaderParser\HeaderParserError
Definition
HeaderParserError.php:5
$s
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
Definition
mergeMessageFileList.php:206
MediaWiki\Rest\HeaderParser
Definition
HeaderParserBase.php:3
includes
Rest
HeaderParser
HeaderParserBase.php
Generated on Fri Apr 5 2024 23:40:46 for MediaWiki by
1.9.8