From 5da06ab009079b9999e207da9a8f325358efcd25 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Fri, 20 Jun 2008 06:34:56 +0000 Subject: [PATCH] ICU-6367 update space handling for java X-SVN-Rev: 24251 --- .../format/NumberFormatRegressionTest.java | 42 +++++++++++++++++++ icu4j/src/com/ibm/icu/text/DecimalFormat.java | 4 ++ 2 files changed, 46 insertions(+) diff --git a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java index 1b8909a36f3..4893c7ec40c 100644 --- a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java @@ -281,4 +281,46 @@ public class NumberFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk { } } } + + void checkNBSPPatternRtNum(String testcase, NumberFormat nf, double myNumber) { + String myString = nf.format(myNumber); + + double aNumber; + try { + aNumber = nf.parse(myString).doubleValue(); + } catch (ParseException e) { + // TODO Auto-generated catch block + errln("FAIL: " + testcase +" - failed to parse. " + e.toString()); + return; + } + if(Math.abs(aNumber-myNumber)>.001) { + errln("FAIL: "+testcase+": formatted "+myNumber+", parsed into "+aNumber+"\n"); + } else { + logln("PASS: "+testcase+": formatted "+myNumber+", parsed into "+aNumber+"\n"); + } + } + + void checkNBSPPatternRT(String testcase, NumberFormat nf) { + checkNBSPPatternRtNum(testcase, nf, 12345.); + checkNBSPPatternRtNum(testcase, nf, -12345.); + } + + public void TestNBSPInPattern() { + NumberFormat nf = null; + String testcase; + + + testcase="ar_AE UNUM_CURRENCY"; + nf = NumberFormat.getCurrencyInstance(new ULocale("ar_AE")); + checkNBSPPatternRT(testcase, nf); + // if we don't have CLDR 1.6 data, bring out the problem anyways + + String SPECIAL_PATTERN = "\u00A4\u00A4'\u062f.\u0625.\u200f\u00a0'###0.00"; + testcase = "ar_AE special pattern: " + SPECIAL_PATTERN; + nf = new DecimalFormat(); + ((DecimalFormat)nf).applyPattern(SPECIAL_PATTERN); + checkNBSPPatternRT(testcase, nf); + + } + } diff --git a/icu4j/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/src/com/ibm/icu/text/DecimalFormat.java index 9a2aec0ad9e..bbeeb928e2e 100644 --- a/icu4j/src/com/ibm/icu/text/DecimalFormat.java +++ b/icu4j/src/com/ibm/icu/text/DecimalFormat.java @@ -2255,6 +2255,10 @@ public class DecimalFormat extends NumberFormat { if (pos == s && !literalMatch) { return -1; } + // If we skip UWhiteSpace in the input text, we need to skip it in the pattern. + // Otherwise, the previous lines may have skipped over text (such as U+00A0) that + // is also in the affix. + i = skipUWhiteSpace(affix, i); } else { if (pos < input.length() && UTF16.charAt(input, pos) == c) {