From 946d320413c8bf12f0541f25fab6dd868d84c2d5 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Fri, 28 Sep 2012 18:46:48 +0000 Subject: [PATCH] ICU-9612 Make single quote logic processing correct. X-SVN-Rev: 32463 --- .../ibm/icu/text/CompactDecimalDataCache.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java b/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java index 0535a91dd3..6fdb42ab7e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java @@ -81,6 +81,12 @@ class CompactDecimalDataCache { this.longData = longData; } } + + private static enum QuoteState { + OUTSIDE, // Outside single quote + INSIDE_EMPTY, // Just inside single quote + INSIDE_FULL // Inside single quote along with characters + } /** @@ -291,7 +297,33 @@ class CompactDecimalDataCache { } private static String fixQuotes(String prefixOrSuffix) { - return prefixOrSuffix.replace("'.'", "."); + StringBuilder result = new StringBuilder(); + int len = prefixOrSuffix.length(); + QuoteState state = QuoteState.OUTSIDE; + for (int idx = 0; idx < len; idx++) { + char ch = prefixOrSuffix.charAt(idx); + if (ch == '\'') { + if (state == QuoteState.INSIDE_EMPTY) { + result.append('\''); + } + } else { + result.append(ch); + } + + // Update state + switch (state) { + case OUTSIDE: + state = ch == '\'' ? QuoteState.INSIDE_EMPTY : QuoteState.OUTSIDE; + break; + case INSIDE_EMPTY: + case INSIDE_FULL: + state = ch == '\'' ? QuoteState.OUTSIDE : QuoteState.INSIDE_FULL; + break; + default: + throw new IllegalStateException(); + } + } + return result.toString(); } /**