You are here

private static function Inline::parseMapping in Loft Data Grids 6.2

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

Parses a mapping to a YAML string.

Parameters

string $mapping:

int &$i:

array $references:

Return value

string A YAML string

Throws

ParseException When malformed inline YAML string is parsed

2 calls to Inline::parseMapping()
Inline::parse in vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php
Converts a YAML string to a PHP array.
Inline::parseSequence in vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php
Parses a sequence to a YAML string.

File

vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php, line 351

Class

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

Namespace

Symfony\Component\Yaml

Code

private static function parseMapping($mapping, &$i = 0, $references = array()) {
  $output = array();
  $len = strlen($mapping);
  ++$i;

  // {foo: bar, bar:foo, ...}
  while ($i < $len) {
    switch ($mapping[$i]) {
      case ' ':
      case ',':
        ++$i;
        continue 2;
      case '}':
        return $output;
    }

    // key
    $key = self::parseScalar($mapping, array(
      ':',
      ' ',
    ), array(
      '"',
      "'",
    ), $i, false);

    // value
    $done = false;
    while ($i < $len) {
      switch ($mapping[$i]) {
        case '[':

          // nested sequence
          $output[$key] = self::parseSequence($mapping, $i, $references);
          $done = true;
          break;
        case '{':

          // nested mapping
          $output[$key] = self::parseMapping($mapping, $i, $references);
          $done = true;
          break;
        case ':':
        case ' ':
          break;
        default:
          $output[$key] = self::parseScalar($mapping, array(
            ',',
            '}',
          ), array(
            '"',
            "'",
          ), $i, true, $references);
          $done = true;
          --$i;
      }
      ++$i;
      if ($done) {
        continue 2;
      }
    }
  }
  throw new ParseException(sprintf('Malformed inline YAML string %s', $mapping));
}