You are here

private static function Inline::parseSequence in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::parseSequence()
  2. 7.2 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::parseSequence()

Parses a sequence to a YAML string.

Parameters

string $sequence:

integer &$i:

Return value

string A YAML string

Throws

ParseException When malformed inline YAML string is parsed

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

File

vendor/Symfony/Component/Yaml/Inline.php, line 268

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) {
  $output = array();
  $len = strlen($sequence);
  $i += 1;

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

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

        // nested mapping
        $output[] = self::parseMapping($sequence, $i);
        break;
      case ']':
        return $output;
      case ',':
      case ' ':
        break;
      default:
        $isQuoted = in_array($sequence[$i], array(
          '"',
          "'",
        ));
        $value = self::parseScalar($sequence, array(
          ',',
          ']',
        ), array(
          '"',
          "'",
        ), $i);
        if (!$isQuoted && false !== strpos($value, ': ')) {

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

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