Jump to content

Commatizing numbers: Difference between revisions

m
Line 250:
 
// The first number field begins with zero then no digit, or non-zero.
auto numField = regexctRegex!("0(?![0-9])|[1-9][0-9]*");
auto matchNum = matchFirst(scanSpan, numField);
 
Line 257:
 
// Pass only a point and capture a decimal fractional field, if any.
auto decField = regexctRegex!("(?<=^\\.)[0-9]+");
 
static if (smart) {
Line 276:
}
 
foreachif (pair; specials.byPair != null) {
// There may be special prefixed formats that use different separators.
// Any format with a longer prefix should override a shorter one.
Tuple!(string, string)[] pairs;
foreach (pair; specials.byPair) {
pairs ~=foreach (pair; specials.byPair) {
pairs ~= pair;
}
std.algorithm.sort!("a[0].length < b[0].length")(pairs);
foreach (symbol; pairs) {
ifauto preAnyDigit = (matchNum.pre.length >= symbol[stripRight('0].length && ');
foreach (symbol[0]; ==pairs) matchNum.pre[$ - symbol[0].length .. $]){
insif (preAnyDigit.length >= symbol[10];.length &&
symbol[0] == preAnyDigit[$ - symbol[0].length .. $])
ins = symbol[1];
}
}
 
Line 307 ⟶ 310:
assert("1000 2.3000".commatize == "1,000 2.3000");
assert("0001123.456789".commatize == "0001,123.456,789");
assert("Z$01000".commatize(0, 3, ",", ["Z$":" "]) == "Z$01 000");
}</lang>
{{out}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.