| @@ 6-34 (lines=29) @@ | ||
| 3 | /** |
|
| 4 | * Handler for escaped string |
|
| 5 | */ |
|
| 6 | class xKerman_Restricted_EscapedStringHandler implements xKerman_Restricted_HandlerInterface |
|
| 7 | { |
|
| 8 | /** @var integer */ |
|
| 9 | const CLOSE_STRING_LENGTH = 2; |
|
| 10 | /** |
|
| 11 | * parse given `$source` as escaped string |
|
| 12 | * |
|
| 13 | * @param Source $source parser input |
|
| 14 | * @param string $args string length |
|
| 15 | * @return array |
|
| 16 | * @throws UnserializeFailedException |
|
| 17 | */ |
|
| 18 | public function handle(xKerman_Restricted_Source $source, $args) |
|
| 19 | { |
|
| 20 | $length = intval($args, 10); |
|
| 21 | $result = array(); |
|
| 22 | for ($i = 0; $i < $length; ++$i) { |
|
| 23 | $char = $source->read(1); |
|
| 24 | if ($char !== '\\') { |
|
| 25 | $result[] = $char; |
|
| 26 | continue; |
|
| 27 | } |
|
| 28 | $hex = $source->match('/\\G([0-9a-fA-F]{2})/'); |
|
| 29 | $result[] = chr(base_convert($hex[0], 16, 10)); |
|
| 30 | } |
|
| 31 | $source->consume('";', self::CLOSE_STRING_LENGTH); |
|
| 32 | return array(implode('', $result), $source); |
|
| 33 | } |
|
| 34 | } |
|
| @@ 10-39 (lines=30) @@ | ||
| 7 | /** |
|
| 8 | * Handler for escaped string |
|
| 9 | */ |
|
| 10 | class EscapedStringHandler implements HandlerInterface |
|
| 11 | { |
|
| 12 | /** @var integer */ |
|
| 13 | const CLOSE_STRING_LENGTH = 2; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * parse given `$source` as escaped string |
|
| 17 | * |
|
| 18 | * @param Source $source parser input |
|
| 19 | * @param string $args string length |
|
| 20 | * @return array |
|
| 21 | * @throws UnserializeFailedException |
|
| 22 | */ |
|
| 23 | public function handle(Source $source, $args) |
|
| 24 | { |
|
| 25 | $length = intval($args, 10); |
|
| 26 | $result = array(); |
|
| 27 | for ($i = 0; $i < $length; ++$i) { |
|
| 28 | $char = $source->read(1); |
|
| 29 | if ($char !== '\\') { |
|
| 30 | $result[] = $char; |
|
| 31 | continue; |
|
| 32 | } |
|
| 33 | $hex = $source->match('/\G([0-9a-fA-F]{2})/'); |
|
| 34 | $result[] = chr(base_convert($hex[0], 16, 10)); |
|
| 35 | } |
|
| 36 | $source->consume('";', self::CLOSE_STRING_LENGTH); |
|
| 37 | return array(implode('', $result), $source); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ||