Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractUnicodeString.php

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\String

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal