function AbstractUnicodeString::width
Overrides AbstractString::width
File
-
vendor/
symfony/ string/ AbstractUnicodeString.php, line 498
Class
- AbstractUnicodeString
- Represents a string of abstract Unicode characters.
Namespace
Symfony\Component\StringCode
public function width(bool $ignoreAnsiDecoration = true) : int {
$width = 0;
$s = str_replace([
"\x00",
"\x05",
"\x07",
], '', $this->string);
if (str_contains($s, "\r")) {
$s = str_replace([
"\r\n",
"\r",
], "\n", $s);
}
if (!$ignoreAnsiDecoration) {
$s = preg_replace('/[\\p{Cc}\\x7F]++/u', '', $s);
}
foreach (explode("\n", $s) as $s) {
if ($ignoreAnsiDecoration) {
$s = preg_replace('/(?:\\x1B(?:
\\[ [\\x30-\\x3F]*+ [\\x20-\\x2F]*+ [\\x40-\\x7E]
| [P\\]X^_] .*? \\x1B\\\\
| [\\x41-\\x7E]
)|[\\p{Cc}\\x7F]++)/xu', '', $s);
}
$lineWidth = $this->wcswidth($s);
if ($lineWidth > $width) {
$width = $lineWidth;
}
}
return $width;
}