blob: aa6e5f43ea4493db6456ba42eac2ce12572788d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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;
}
}
|