MbString::tokenizeFormat()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace Popy\Calendar\Parser\FormatLexer;
4
5
use Popy\Calendar\Parser\FormatToken;
6
use Popy\Calendar\Parser\FormatLexerInterface;
7
8
/**
9
 * mb_string based implementation.
10
 */
11
class MbString implements FormatLexerInterface
12
{
13
    /**
14
     * @inheritDoc
15
     */
16
    public function tokenizeFormat($format)
17
    {
18
        $res = [];
19
        $escaped = false;
20
        $length = mb_strlen($format);
21
22
        for ($i=0; $i < $length; $i++) {
23
            $symbol = mb_substr($format, $i, 1);
24
25
            if ($escaped) {
26
                $escaped = false;
27
                $res[] = new FormatToken($symbol, FormatToken::TYPE_LITTERAL);
28
                continue;
29
            }
30
31
            if ($symbol === '\\') {
32
                $escaped = true;
33
                continue;
34
            }
35
36
            $res[] = new FormatToken($symbol, FormatToken::TYPE_SYMBOL);
37
        }
38
39
        $res[] = new FormatToken(null, FormatToken::TYPE_EOF);
40
41
        return $res;
42
    }
43
}
44