Passed
Push — master ( 4fdb23...efd6a0 )
by Hannes
08:07
created

MultibyteHack.php ➔ substr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of byrokrat\autogiro.
5
 *
6
 * byrokrat\autogiro is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * byrokrat\autogiro is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with byrokrat\autogiro. If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Copyright 2016-20 Hannes Forsgård
20
 */
21
22
declare(strict_types=1);
23
24
namespace byrokrat\autogiro\Parser;
25
26
/**
27
 * Hack to make the phpeg Grammar use multibyte processing
28
 *
29
 * By extending this class the strlen() and substr() functions will automatically
30
 * be imported to the Parser namespace and replace the standard functions with
31
 * their multibyte equivalents.
32
 */
33
class MultibyteHack
34
{
35
}
36
37
/**
38
 * @param string $str
39
 * @return int
40
 */
41
function strlen($str)
42
{
43
    return mb_strlen($str);
44
}
45
46
/**
47
 * @param string $str
48
 * @param int $start
49
 * @param int $length
50
 * @return string
51
 */
52
function substr($str, $start, $length)
53
{
54
    return mb_substr($str, $start, $length);
55
}
56