/** * Sets the input data to be tokenized. * * @param string $input The input to be tokenized. */ public function setSource(Source\String $source) { /*{{{*/ $this->source = $source; $this->encoding = $source->getEncoding(); $this->is_ascii = Encoding::isSameEncoding($this->encoding, 'ascii'); mb_regex_encoding($this->encoding); $this->lines = $source->getLines(); $this->numlines = $source->getNumLines(); $this->reset(); }
/** * Detects a Css StyleSheet's charset according to the spec. * * @param string $text The stylesheet's text * * @return string The detected charset or false **/ public static function detect($text) { foreach (self::$CHARSET_DETECTION_MAP as $charset_map) { $pattern = $charset_map['pattern']; $matches = array(); if (preg_match('#^' . $pattern . '#U', $text, $matches)) { if ($charset_map['charset']) { $charset = $charset_map['charset']; } else { $charset = $matches[1]; } return $charset; } } return parent::detect($text); }
/** * @dataProvider testIsSameEncodingProvider **/ public function testIsSameEncoding($encoding_1, $encoding_2, $expected) { $this->assertEquals($expected, Encoding::isSameEncoding($encoding_1, $encoding_2)); }
/** * Sets the input data to be tokenized. * * @param SourceInterface $source The input to be tokenized. */ public function setSource(SourceInterface $source) { /*{{{*/ $this->source = $source; $this->encoding = $source->getEncoding(); $this->is_ascii = Encoding::isSameEncoding($this->encoding, 'ascii'); $this->multibyte = $this->unicode && !$this->is_ascii; mb_regex_encoding($this->encoding); //$this->lines = $source->getLines(); //$this->numlines = $source->getNumLines(); $this->numlines = count($source); $this->reset(); }