From e16119ade72760d797f31f31328d16d20abead4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Thu, 10 Mar 2016 15:55:22 +0100 Subject: [PATCH] Unify token matching in Format{DateTime,Number}ToParts --- src/11.numberformat.js | 15 +++++++-------- src/12.datetimeformat.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/11.numberformat.js b/src/11.numberformat.js index b777dd13..94887384 100644 --- a/src/11.numberformat.js +++ b/src/11.numberformat.js @@ -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)) @@ -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. @@ -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); } diff --git a/src/12.datetimeformat.js b/src/12.datetimeformat.js index b20e2fb7..93e31bb7 100644 --- a/src/12.datetimeformat.js +++ b/src/12.datetimeformat.js @@ -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.