@@ -51,6 +51,7 @@ class CliDumper extends AbstractDumper
51
51
"\r" => '\r ' ,
52
52
"\033" => '\e ' ,
53
53
];
54
+ protected static $ unicodeCharsRx = "/[ \u{00A0}\u{00AD}\u{034F}\u{061C}\u{115F}\u{1160}\u{17B4}\u{17B5}\u{180E}\u{2000}- \u{200F}\u{202F}\u{205F}\u{2060}- \u{2064}\u{206A}- \u{206F}\u{3000}\u{2800}\u{3164}\u{FEFF}\u{FFA0}\u{1D159}\u{1D173}- \u{1D17A}]/u " ;
54
55
55
56
protected $ collapseNextHash = false ;
56
57
protected $ expandNextHash = false ;
@@ -224,7 +225,6 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
224
225
$ this ->line .= $ this ->indentPad ;
225
226
}
226
227
if ('' !== $ str ) {
227
- $ str = $ this ->replaceInvisibleCharacters ($ str );
228
228
$ this ->line .= $ this ->style ('str ' , $ str , $ attr );
229
229
}
230
230
if ($ i ++ == $ m ) {
@@ -349,7 +349,6 @@ protected function dumpKey(Cursor $cursor)
349
349
if (\is_int ($ key )) {
350
350
$ this ->line .= $ this ->style ($ style , $ key ).' => ' ;
351
351
} else {
352
- $ key = $ this ->replaceInvisibleCharacters ($ key );
353
352
$ this ->line .= $ bin .'" ' .$ this ->style ($ style , $ key ).'" => ' ;
354
353
}
355
354
break ;
@@ -452,6 +451,14 @@ protected function style(string $style, string $value, array $attr = []): string
452
451
return $ s .$ endCchr ;
453
452
}, $ value , -1 , $ cchrCount );
454
453
454
+ if (!($ attr ['binary ' ] ?? false )) {
455
+ $ value = preg_replace_callback (static ::$ unicodeCharsRx , function ($ c ) use (&$ cchrCount , $ startCchr , $ endCchr ) {
456
+ ++$ cchrCount ;
457
+
458
+ return $ startCchr .'\u{ ' .strtoupper (dechex (mb_ord ($ c [0 ]))).'} ' .$ endCchr ;
459
+ }, $ value );
460
+ }
461
+
455
462
if ($ this ->colors ) {
456
463
if ($ cchrCount && "\033" === $ value [0 ]) {
457
464
$ value = substr ($ value , \strlen ($ startCchr ));
@@ -615,16 +622,4 @@ private function getSourceLink(string $file, int $line)
615
622
616
623
return false ;
617
624
}
618
-
619
- /**
620
- * Replace invisible character by the hexadecimal representation of the codepoint.
621
- */
622
- private function replaceInvisibleCharacters (string $ input ): string
623
- {
624
- $ invisibleCharacters = [' ' ];
625
-
626
- return preg_replace_callback ('/ ' .implode ('| ' , $ invisibleCharacters ).'/u ' , static function (array $ matches ): string {
627
- return sprintf ('\u{%s} ' , dechex (mb_ord ($ matches [0 ])));
628
- }, $ input );
629
- }
630
625
}
0 commit comments