You are here

private function Parser::cleanup in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Parser.php \Symfony\Component\Yaml\Parser::cleanup()

Cleanups a YAML string to be parsed.

Parameters

string $value The input YAML string:

Return value

string A cleaned up YAML string

1 call to Parser::cleanup()
Parser::parse in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Parser.php
Parses a YAML string to a PHP value.

File

modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Parser.php, line 625

Class

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

Namespace

Symfony\Component\Yaml

Code

private function cleanup($value) {
  $value = str_replace(array(
    "\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 ($count == 1) {

    // 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 ($count == 1) {

    // 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*$#s', '', $value);
  }
  return $value;
}