private function Parser::parseFoldedScalar in Service Container 7
Same name and namespace in other branches
- 7.2 modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Parser.php \Symfony\Component\Yaml\Parser::parseFoldedScalar()
Parses a folded scalar.
Parameters
string $separator The separator that was used to begin this folded scalar (| or >):
string $indicator The indicator that was used to begin this folded scalar (+ or -):
int $indentation The indentation that was used to begin this folded scalar:
Return value
string The text value
1 call to Parser::parseFoldedScalar()
- Parser::parseValue in modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ Yaml/ Parser.php - Parses a YAML value.
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ Yaml/ Parser.php, line 485
Class
- Parser
- Parser parses YAML strings to convert them to PHP arrays.
Namespace
Symfony\Component\YamlCode
private function parseFoldedScalar($separator, $indicator = '', $indentation = 0) {
$notEOF = $this
->moveToNextLine();
if (!$notEOF) {
return '';
}
$isCurrentLineBlank = $this
->isCurrentLineBlank();
$text = '';
// leading blank lines are consumed before determining indentation
while ($notEOF && $isCurrentLineBlank) {
// newline only if not EOF
if ($notEOF = $this
->moveToNextLine()) {
$text .= "\n";
$isCurrentLineBlank = $this
->isCurrentLineBlank();
}
}
// determine indentation if not specified
if (0 === $indentation) {
if (preg_match('/^ +/', $this->currentLine, $matches)) {
$indentation = strlen($matches[0]);
}
}
if ($indentation > 0) {
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
while ($notEOF && ($isCurrentLineBlank || preg_match($pattern, $this->currentLine, $matches))) {
if ($isCurrentLineBlank) {
$text .= substr($this->currentLine, $indentation);
}
else {
$text .= $matches[1];
}
// newline only if not EOF
if ($notEOF = $this
->moveToNextLine()) {
$text .= "\n";
$isCurrentLineBlank = $this
->isCurrentLineBlank();
}
}
}
elseif ($notEOF) {
$text .= "\n";
}
if ($notEOF) {
$this
->moveToPreviousLine();
}
// replace all non-trailing single newlines with spaces in folded blocks
if ('>' === $separator) {
preg_match('/(\\n*)$/', $text, $matches);
$text = preg_replace('/(?<!\\n)\\n(?!\\n)/', ' ', rtrim($text, "\n"));
$text .= $matches[1];
}
// deal with trailing newlines as indicated
if ('' === $indicator) {
$text = preg_replace('/\\n+$/s', "\n", $text);
}
elseif ('-' === $indicator) {
$text = preg_replace('/\\n+$/s', '', $text);
}
return $text;
}