]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/cldr-plural-rule-parser/src/Converter/Fragment.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / cldr-plural-rule-parser / src / Converter / Fragment.php
1 <?php
2 /**
3  * @author Niklas Laxström, Tim Starling
4  * @license GPL-2.0+
5  * @file
6  */
7
8 namespace CLDRPluralRuleParser\Converter;
9
10 use CLDRPluralRuleParser\Error;
11 use CLDRPluralRuleParser\Converter;
12
13 /**
14  * Helper for Converter.
15  * The base class for operators and expressions, describing a region of the input string.
16  */
17 class Fragment {
18         public $parser, $pos, $length, $end;
19
20         function __construct( Converter $parser, $pos, $length ) {
21                 $this->parser = $parser;
22                 $this->pos = $pos;
23                 $this->length = $length;
24                 $this->end = $pos + $length;
25         }
26
27         public function error( $message ) {
28                 $text = $this->getText();
29                 throw new Error( "$message at position " . ( $this->pos + 1 ) . ": \"$text\"" );
30         }
31
32         public function getText() {
33                 return substr( $this->parser->rule, $this->pos, $this->length );
34         }
35 }