26
26
*/
27
27
class Parser {
28
28
29
+ private $ sText ;
29
30
private $ aText ;
30
31
private $ iCurrentPosition ;
31
32
private $ oParserSettings ;
@@ -35,16 +36,12 @@ class Parser {
35
36
private $ aSizeUnits ;
36
37
37
38
public function __construct ($ sText , Settings $ oParserSettings = null ) {
39
+ $ this ->sText = $ sText ;
38
40
$ this ->iCurrentPosition = 0 ;
39
41
if ($ oParserSettings === null ) {
40
42
$ oParserSettings = Settings::create ();
41
43
}
42
44
$ this ->oParserSettings = $ oParserSettings ;
43
- if ($ this ->oParserSettings ->bMultibyteSupport ) {
44
- $ this ->aText = preg_split ('//u ' , $ sText , null , PREG_SPLIT_NO_EMPTY );
45
- } else {
46
- $ this ->aText = str_split ($ sText );
47
- }
48
45
$ this ->blockRules = explode ('/ ' , AtRule::BLOCK_RULES );
49
46
50
47
foreach (explode ('/ ' , Size::ABSOLUTE_SIZE_UNITS .'/ ' .Size::RELATIVE_SIZE_UNITS .'/ ' .Size::NON_SIZE_UNITS ) as $ val ) {
@@ -59,6 +56,7 @@ public function __construct($sText, Settings $oParserSettings = null) {
59
56
60
57
public function setCharset ($ sCharset ) {
61
58
$ this ->sCharset = $ sCharset ;
59
+ $ this ->aText = $ this ->strsplit ($ this ->sText );
62
60
$ this ->iLength = count ($ this ->aText );
63
61
}
64
62
@@ -622,6 +620,23 @@ private function strtolower($sString) {
622
620
}
623
621
}
624
622
623
+ private function strsplit ($ sString ) {
624
+ if ($ this ->oParserSettings ->bMultibyteSupport ) {
625
+ if ($ this ->streql ($ this ->sCharset , 'utf-8 ' )) {
626
+ return preg_split ('//u ' , $ sString , null , PREG_SPLIT_NO_EMPTY );
627
+ } else {
628
+ $ iLength = mb_strlen ($ sString , $ this ->sCharset );
629
+ $ out = [];
630
+ for ($ i = 0 ; $ i < $ iLength ; ++$ i ) {
631
+ $ out [] = mb_substr ($ sString , $ i , 1 , $ this ->sCharset );
632
+ }
633
+ return $ out ;
634
+ }
635
+ } else {
636
+ return str_split ($ sString );
637
+ }
638
+ }
639
+
625
640
private function strpos ($ sString , $ sNeedle , $ iOffset ) {
626
641
if ($ this ->oParserSettings ->bMultibyteSupport ) {
627
642
return mb_strpos ($ sString , $ sNeedle , $ iOffset , $ this ->sCharset );
0 commit comments