1<?php 2/** 3* Double quote string status for the scanner 4* 5* @license http://www.opensource.org/licenses/mit-license.php The MIT License 6* @copyright Copyright 2010-2014 PhpCss Team 7*/ 8 9namespace PhpCss\Scanner\Status\Text { 10 11 use PhpCss\Scanner; 12 13 /** 14 * Double quote string status for the scanner 15 */ 16 class Double extends Scanner\Status { 17 18 /** 19 * Try to get token in buffer at offset position. 20 * 21 * @param string $buffer 22 * @param integer $offset 23 * @return Scanner\Token 24 */ 25 public function getToken(string $buffer, int $offset): ?Scanner\Token { 26 if ('"' === substr($buffer, $offset, 1)) { 27 return new Scanner\Token( 28 Scanner\Token::DOUBLEQUOTE_STRING_END, '"', $offset 29 ); 30 } 31 $tokenString = substr($buffer, $offset, 2); 32 if ('\\"' === $tokenString || '\\\\' === $tokenString) { 33 return new Scanner\Token( 34 Scanner\Token::STRING_ESCAPED_CHARACTER, $tokenString, $offset 35 ); 36 } 37 $tokenString = $this->matchPattern( 38 $buffer, $offset, '([^\\\\"]+)S' 39 ); 40 if (!empty($tokenString)) { 41 return new Scanner\Token( 42 Scanner\Token::STRING_CHARACTERS, $tokenString, $offset 43 ); 44 } 45 return NULL; 46 } 47 48 /** 49 * Check if token ends status 50 * 51 * @param Scanner\Token $token 52 * @return bool 53 */ 54 public function isEndToken(Scanner\Token$token): bool { 55 return ( 56 $token->type === Scanner\Token::DOUBLEQUOTE_STRING_END 57 ); 58 } 59 60 /** 61 * Get new (sub)status if needed. 62 * 63 * @param Scanner\Token $token 64 * @return Scanner\Status|NULL 65 */ 66 public function getNewStatus(Scanner\Token $token): ?Scanner\Status { 67 return NULL; 68 } 69 } 70} 71