diff options
author | Mario <mario@mariovavti.com> | 2019-11-10 12:49:51 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-11-10 14:10:03 +0100 |
commit | 580c3f4ffe9608d2beb56d418c68b3b112420e76 (patch) | |
tree | 82335d01179ac361d3f547a4b8e8c598d302e9f3 /vendor/commerceguys/intl/src/Formatter/ParsedPattern.php | |
parent | d22766f458a8539a40a57f3946459a9be1f21cd6 (diff) | |
download | volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.tar.gz volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.tar.bz2 volse-hubzilla-580c3f4ffe9608d2beb56d418c68b3b112420e76.zip |
another bulk of composer updates
(cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce)
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; + } +} |