You are here

protected function IntegerFormatter::patternSymbolsSplit in Currency 7.2

Splits a pattern into two fragments.

Parameters

array $symbols: An array of NumberPatternSymbol objects.

string $separator:

boolean $optional_right_fragment: Whether the symbols on the right side of the separator, and, because of that, the separator itself are optional.

Return value

array An array of NumberPatternSymbol objects.

Throws

\InvalidArgumentException

\RuntimeException

2 calls to IntegerFormatter::patternSymbolsSplit()
DecimalFormatter::__construct in currency/vendor/bartfeenstra/cldr/src/BartFeenstra/CLDR/DecimalFormatter.php
Overrides parent::__construct().
IntegerFormatter::__construct in currency/vendor/bartfeenstra/cldr/src/BartFeenstra/CLDR/IntegerFormatter.php
Implements __construct().

File

currency/vendor/bartfeenstra/cldr/src/BartFeenstra/CLDR/IntegerFormatter.php, line 223
Contains class \BartFeenstra\CLDR\IntegerFormatter.

Class

IntegerFormatter
Formats an integer according CLDR number pattern guidelines.

Namespace

BartFeenstra\CLDR

Code

protected function patternSymbolsSplit(array $symbols, $separator, $optional_right_fragment = FALSE) {
  $separator_position = NULL;
  foreach ($symbols as $position => $symbol) {
    if (!$symbol instanceof NumberPatternSymbol) {
      throw new \InvalidArgumentException();
    }
    if ($symbol->symbol === $separator && !$symbol->escaped) {
      if (is_null($separator_position)) {
        $separator_position = $position;
      }
      else {
        throw new \RunTimeException("Illegal separator ({$separator}) at position {$symbol->position}.");
      }
    }
  }
  if (!$separator_position) {
    if ($optional_right_fragment) {
      return array(
        $symbols,
        FALSE,
      );
    }
    throw new \RunTimeException("Missing separator ({$separator}).");
  }
  else {
    return array(
      array_slice($symbols, 0, $separator_position),
      array_slice($symbols, $separator_position + 1),
    );
  }
}