You are here

public static function Inline::parseScalar in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::parseScalar()

Parses a YAML scalar.

@internal

Parameters

string $scalar:

string[] $delimiters:

string[] $stringDelimiters:

int &$i:

bool $evaluate:

array $references:

Return value

string

Throws

ParseException When malformed inline YAML string is parsed

6 calls to Inline::parseScalar()
Inline::evaluateScalar in vendor/symfony/yaml/Inline.php
Evaluates scalars and replaces magic values.
Inline::parse in vendor/symfony/yaml/Inline.php
Converts a YAML string to a PHP value.
Inline::parseMapping in vendor/symfony/yaml/Inline.php
Parses a YAML mapping.
Inline::parseSequence in vendor/symfony/yaml/Inline.php
Parses a YAML sequence.
InlineTest::testParseScalarWithCorrectlyQuotedStringShouldReturnString in vendor/symfony/yaml/Tests/InlineTest.php

... See full list

File

vendor/symfony/yaml/Inline.php, line 228

Class

Inline
Inline implements a YAML parser/dumper for the YAML inline syntax.

Namespace

Symfony\Component\Yaml

Code

public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array(
  '"',
  "'",
), &$i = 0, $evaluate = true, $references = array()) {
  if (in_array($scalar[$i], $stringDelimiters)) {

    // quoted scalar
    $output = self::parseQuotedScalar($scalar, $i);
    if (null !== $delimiters) {
      $tmp = ltrim(substr($scalar, $i), ' ');
      if (!in_array($tmp[0], $delimiters)) {
        throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)));
      }
    }
  }
  else {

    // "normal" string
    if (!$delimiters) {
      $output = substr($scalar, $i);
      $i += strlen($output);

      // remove comments
      if (Parser::preg_match('/[ \\t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
        $output = substr($output, 0, $match[0][1]);
      }
    }
    elseif (Parser::preg_match('/^(.+?)(' . implode('|', $delimiters) . ')/', substr($scalar, $i), $match)) {
      $output = $match[1];
      $i += strlen($output);
    }
    else {
      throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar));
    }

    // a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
    if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) {
      @trigger_error(sprintf('Not quoting the scalar "%s" starting with "%s" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $output, $output[0]), E_USER_DEPRECATED);

      // to be thrown in 3.0
      // throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
    }
    if ($evaluate) {
      $output = self::evaluateScalar($output, $references);
    }
  }
  return $output;
}