Skip to content

Commit

Permalink
Unify token matching in Format{DateTime,Number}ToParts
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Mar 10, 2016
1 parent 08f4c7d commit e16119a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src/11.numberformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,9 @@ function FormatNumberToParts (numberFormat, x) {
if (beginIndex > nextIndex)
arrPush.call(result, { type: 'literal', value: pattern.substring(nextIndex, beginIndex) });

nextIndex = endIndex + 1;

let p = pattern.substring(beginIndex, nextIndex);
let p = pattern.substring(beginIndex + 1, endIndex);

if (p === '{number}') {
if (p === 'number') {
if (isNaN(x))
arrPush.call(result, { type: 'nan', value: ild.nan });
if (!isFinite(x))
Expand Down Expand Up @@ -571,13 +569,13 @@ function FormatNumberToParts (numberFormat, x) {
arrPush.call(result, { type: 'fraction', value: fraction });
}

} else if (p === '{plusSign}') {
} else if (p === 'plusSign') {
arrPush.call(result, { type: 'plusSign', value: ild.plusSign });
} else if (p === '{minusSign}') {
} else if (p === 'minusSign') {
arrPush.call(result, { type: 'minusSign', value: ild.minusSign });
} else if (p === '{percentSign}' && internal['[[style]]'] === 'percent') {
arrPush.call(result, { type: 'percentSign', value: ild.percentSign });
} else if (p === '{currency}' && internal['[[style]]'] === 'currency') {
} else if (p === 'currency' && internal['[[style]]'] === 'currency') {
let cd,
// a. Let currency be the value of the [[currency]] internal property of
// numberFormat.
Expand Down Expand Up @@ -609,9 +607,10 @@ function FormatNumberToParts (numberFormat, x) {

arrPush.call(result, { type: 'currency', value: cd });
} else {
arrPush.call(result, { type: 'literal', value: p });
arrPush.call(result, { type: 'literal', value: pattern.substring(beginIndex, endIndex + 1) });
}

nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}

Expand Down
2 changes: 1 addition & 1 deletion src/12.datetimeformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ function CreateDateTimeParts(dateTimeFormat, x) {
} else {
arrPush.call(result, {
type: 'literal',
value: pattern.substring(beginIndex, endIndex),
value: pattern.substring(beginIndex, endIndex + 1),
});
}
// h.
Expand Down

0 comments on commit e16119a

Please sign in to comment.