You are here

private static function Inline::parseSequence 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::parseSequence()

Parses a YAML sequence.

Parameters

string $sequence:

int &$i:

array $references:

Return value

array

Throws

ParseException When malformed inline YAML string is parsed

2 calls to Inline::parseSequence()
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.

File

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

Class

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

Namespace

Symfony\Component\Yaml

Code

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

  // [foo, bar, ...]
  while ($i < $len) {
    switch ($sequence[$i]) {
      case '[':

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

        // nested mapping
        $output[] = self::parseMapping($sequence, $i, $references);
        break;
      case ']':
        return $output;
      case ',':
      case ' ':
        break;
      default:
        $isQuoted = in_array($sequence[$i], array(
          '"',
          "'",
        ));
        $value = self::parseScalar($sequence, array(
          ',',
          ']',
        ), array(
          '"',
          "'",
        ), $i, true, $references);

        // the value can be an array if a reference has been resolved to an array var
        if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) {

          // embedded mapping?
          try {
            $pos = 0;
            $value = self::parseMapping('{' . $value . '}', $pos, $references);
          } catch (\InvalidArgumentException $e) {

            // no, it's not
          }
        }
        $output[] = $value;
        --$i;
    }
    ++$i;
  }
  throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence));
}