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

Breadcrumb

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

function Parser::cleanup

1 call to Parser::cleanup()
Parser::doParse in vendor/symfony/yaml/Parser.php

File

vendor/symfony/yaml/Parser.php, line 980

Class

Parser
Parser parses YAML strings to convert them to PHP arrays.

Namespace

Symfony\Component\Yaml

Code

private function cleanup(string $value) : string {
    $value = str_replace([
        "\r\n",
        "\r",
    ], "\n", $value);
    // strip YAML header
    $count = 0;
    $value = preg_replace('#^\\%YAML[: ][\\d\\.]+.*\\n#u', '', $value, -1, $count);
    $this->offset += $count;
    // remove leading comments
    $trimmedValue = preg_replace('#^(\\#.*?\\n)+#s', '', $value, -1, $count);
    if (1 === $count) {
        // items have been removed, update the offset
        $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
        $value = $trimmedValue;
    }
    // remove start of the document marker (---)
    $trimmedValue = preg_replace('#^\\-\\-\\-.*?\\n#s', '', $value, -1, $count);
    if (1 === $count) {
        // items have been removed, update the offset
        $this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
        $value = $trimmedValue;
        // remove end of the document marker (...)
        $value = preg_replace('#\\.\\.\\.\\s*$#', '', $value);
    }
    return $value;
}

API Navigation

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