|
| 1 | +--- Formatter/OutputFormatter.php |
| 2 | ++++ Formatter/OutputFormatter.php |
| 3 | +@@ -12,6 +12,7 @@ |
| 4 | + namespace Symfony\Component\Console\Formatter; |
| 5 | + |
| 6 | + use Symfony\Component\Console\Exception\InvalidArgumentException; |
| 7 | ++use Symfony\Component\Console\Helper\Helper; |
| 8 | + |
| 9 | + use function Symfony\Component\String\b; |
| 10 | + |
| 11 | +@@ -160,9 +161,11 @@ class OutputFormatter implements WrappableOutputFormatterInterface |
| 12 | + continue; |
| 13 | + } |
| 14 | + |
| 15 | ++ // convert byte position to character position. |
| 16 | ++ $pos = Helper::length(substr($message, 0, $pos)); |
| 17 | + // add the text up to the next tag |
| 18 | +- $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
| 19 | +- $offset = $pos + \strlen($text); |
| 20 | ++ $output .= $this->applyCurrentStyle(Helper::substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
| 21 | ++ $offset = $pos + Helper::length($text); |
| 22 | + |
| 23 | + // opening tag? |
| 24 | + if ($open = '/' != $text[1]) { |
| 25 | +@@ -183,7 +186,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | +- $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength); |
| 30 | ++ $output .= $this->applyCurrentStyle(Helper::substr($message, $offset), $output, $width, $currentLineLength); |
| 31 | + |
| 32 | + return strtr($output, ["\0" => '\\', '\\<' => '<', '\\>' => '>']); |
| 33 | + } |
| 34 | +@@ -253,8 +256,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface |
| 35 | + } |
| 36 | + |
| 37 | + if ($currentLineLength) { |
| 38 | +- $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; |
| 39 | +- $text = substr($text, $i); |
| 40 | ++ $prefix = Helper::substr($text, 0, $i = $width - $currentLineLength)."\n"; |
| 41 | ++ $text = Helper::substr($text, $i); |
| 42 | + } else { |
| 43 | + $prefix = ''; |
| 44 | + } |
| 45 | +@@ -270,7 +273,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface |
| 46 | + $lines = explode("\n", $text); |
| 47 | + |
| 48 | + foreach ($lines as $line) { |
| 49 | +- $currentLineLength += \strlen($line); |
| 50 | ++ $currentLineLength += Helper::length($line); |
| 51 | + if ($width <= $currentLineLength) { |
| 52 | + $currentLineLength = 0; |
| 53 | + } |
| 54 | +--- Helper/Helper.php |
| 55 | ++++ Helper/Helper.php |
| 56 | +@@ -100,6 +100,14 @@ abstract class Helper implements HelperInterface |
| 57 | + { |
| 58 | + $string ?? $string = ''; |
| 59 | + |
| 60 | ++ if (preg_match('//u', $string)) { |
| 61 | ++ $result = grapheme_substr((new UnicodeString($string))->toString(), $from, $length); |
| 62 | ++ |
| 63 | ++ return false === $result |
| 64 | ++ ? '' |
| 65 | ++ : $result; |
| 66 | ++ } |
| 67 | ++ |
| 68 | + if (false === $encoding = mb_detect_encoding($string, null, true)) { |
| 69 | + return substr($string, $from, $length); |
| 70 | + } |
0 commit comments