Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
16 / 16 |
MbString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
16 / 16 |
tokenizeFormat | |
100.00% |
1 / 1 |
4 | |
100.00% |
16 / 16 |
<?php | |
namespace Popy\Calendar\Parser\FormatLexer; | |
use Popy\Calendar\Parser\FormatToken; | |
use Popy\Calendar\Parser\FormatLexerInterface; | |
/** | |
* mb_string based implementation. | |
*/ | |
class MbString implements FormatLexerInterface | |
{ | |
/** | |
* @inheritDoc | |
*/ | |
public function tokenizeFormat($format) | |
{ | |
$res = []; | |
$escaped = false; | |
$length = mb_strlen($format); | |
for ($i=0; $i < $length; $i++) { | |
$symbol = mb_substr($format, $i, 1); | |
if ($escaped) { | |
$escaped = false; | |
$res[] = new FormatToken($symbol, FormatToken::TYPE_LITTERAL); | |
continue; | |
} | |
if ($symbol === '\\') { | |
$escaped = true; | |
continue; | |
} | |
$res[] = new FormatToken($symbol, FormatToken::TYPE_SYMBOL); | |
} | |
$res[] = new FormatToken(null, FormatToken::TYPE_EOF); | |
return $res; | |
} | |
} |