diff options
author | Mario <mario@mariovavti.com> | 2019-12-04 10:25:11 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-12-04 10:25:11 +0000 |
commit | bde429cff649237984903a252ba1a718e6d74f53 (patch) | |
tree | b2b2570159cfb37689e6ce3b96c3b1b988d676cc /vendor/commerceguys/intl/src/Formatter/ParsedPattern.php | |
parent | cc9f41df5f83bcab435d6fb941b5a8f5b1457037 (diff) | |
parent | 4c8d33d1eb2a804aa70a7bc677d6c73d0d94816b (diff) | |
download | volse-hubzilla-4.6.tar.gz volse-hubzilla-4.6.tar.bz2 volse-hubzilla-4.6.zip |
Merge branch '4.6RC'4.6
Diffstat (limited to 'vendor/commerceguys/intl/src/Formatter/ParsedPattern.php')
-rw-r--r-- | vendor/commerceguys/intl/src/Formatter/ParsedPattern.php | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/vendor/commerceguys/intl/src/Formatter/ParsedPattern.php b/vendor/commerceguys/intl/src/Formatter/ParsedPattern.php new file mode 100644 index 000000000..aa6e5f43e --- /dev/null +++ b/vendor/commerceguys/intl/src/Formatter/ParsedPattern.php @@ -0,0 +1,129 @@ +<?php + +namespace CommerceGuys\Intl\Formatter; + +/** + * Represents a parsed number pattern. + */ +final class ParsedPattern +{ + /** + * The positive number pattern. + * + * @var string + */ + protected $positivePattern; + + /** + * The negative number pattern. + * + * @var string + */ + protected $negativePattern; + + /** + * Whether grouping is used. + * + * @var bool + */ + protected $groupingUsed; + + /** + * The primary group size. + * + * @var int + */ + protected $primaryGroupSize; + + /** + * The secondary group size. + * + * @var int + */ + protected $secondaryGroupSize; + + /** + * Creates a new ParsedPattern instance. + * + * @param string $pattern The raw pattern. + */ + public function __construct($pattern) + { + // Split the pattern into positive and negative patterns. + $patternList = explode(';', $pattern); + if (!isset($patternList[1])) { + // No explicit negative pattern was provided, construct it. + $patternList[1] = '-' . $patternList[0]; + } + + $this->positivePattern = $patternList[0]; + $this->negativePattern = $patternList[1]; + $this->groupingUsed = (strpos($patternList[0], ',') !== false); + if ($this->groupingUsed) { + preg_match('/#+0/', $patternList[0], $primaryGroupMatches); + $this->primaryGroupSize = $this->secondaryGroupSize = strlen($primaryGroupMatches[0]); + $numberGroups = explode(',', $patternList[0]); + if (count($numberGroups) > 2) { + // This pattern has a distinct secondary group size. + $this->secondaryGroupSize = strlen($numberGroups[1]); + } + } + } + + /** + * Gets the positive number pattern. + * + * Used to format positive numbers. + * + * @return string + */ + public function getPositivePattern() + { + return $this->positivePattern; + } + + /** + * Gets the negative number pattern. + * + * Used to format negative numbers. + * + * @return string + */ + public function getNegativePattern() + { + return $this->negativePattern; + } + + /** + * Gets whether grouping is used. + * + * Indicates that major digits should be grouped according to + * group sizes, right-to-left. + * + * @return bool + */ + public function isGroupingUsed() + { + return $this->groupingUsed; + } + + /** + * Gets the primary group size. + * + * @return int|null + */ + public function getPrimaryGroupSize() + { + return $this->primaryGroupSize; + } + + /** + * Gets the secondary group size. + * + * @return int|null + */ + public function getSecondaryGroupSize() + { + return $this->secondaryGroupSize; + } +} |