From 06f294319e0a6febaa259f87f0a9e1bc7edd3676 Mon Sep 17 00:00:00 2001 From: John Emmons Date: Fri, 17 Feb 2012 23:26:39 +0000 Subject: [PATCH] ICU-7501 Use allowsParsing attribute from CLDR to detect unparseable RBNF rulesets X-SVN-Rev: 31419 --- .../core/src/com/ibm/icu/text/NFRuleSet.java | 21 +++++++++------- .../ibm/icu/text/RuleBasedNumberFormat.java | 24 +------------------ icu4j/main/shared/data/icudata.jar | 4 ++-- icu4j/main/shared/data/icutzdata.jar | 4 ++-- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/NFRuleSet.java b/icu4j/main/classes/core/src/com/ibm/icu/text/NFRuleSet.java index 2d9e9ca056b..32ea6769577 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/NFRuleSet.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/NFRuleSet.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1996-2011, International Business Machines Corporation and * + * Copyright (C) 1996-2012, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -58,6 +58,11 @@ final class NFRuleSet { */ private boolean isFractionRuleSet = false; + /** + * True if the rule set is parseable. + */ + private boolean isParseable = true; + /** * Used to limit recursion for bad rule sets. */ @@ -114,6 +119,11 @@ final class NFRuleSet { throw new IllegalArgumentException("Empty rule set description"); } + if ( name.endsWith("@noparse")) { + name = name.substring(0,name.length()-8); // Remove the @noparse from the name + isParseable = false; + } + // all of the other members of NFRuleSet are initialized // by parseRules() } @@ -385,14 +395,7 @@ final class NFRuleSet { * @return true if the rule set can be used for parsing. */ public boolean isParseable() { - //TODO: - // In CLDR 1.7, we have no distinction between - // parseable/unparseable. Rules which have one of - // 3 suffixes below are know as unparseable for now. - // We should add the information in CLDR data. - return !(name.endsWith("-prefixpart") - || name.endsWith("-postfixpart") - || name.endsWith("-postfx")); + return (isParseable); } //----------------------------------------------------------------------- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java index 2a20da78026..51c6f871830 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/RuleBasedNumberFormat.java @@ -602,11 +602,6 @@ public class RuleBasedNumberFormat extends NumberFormat { private static final boolean DEBUG = ICUDebug.enabled("rbnf"); - // Temporary workaround - when noParse is true, do noting in parse. - // TODO: We need a real fix - see #6895/#6896 - private boolean noParse; - private static final String[] NO_SPELLOUT_PARSE_LANGUAGES = { "ga" }; - //----------------------------------------------------------------------- // constructors //----------------------------------------------------------------------- @@ -791,17 +786,6 @@ public class RuleBasedNumberFormat extends NumberFormat { init(description, localizations); - //TODO: we need a real fix - see #6895 / #6896 - noParse = false; - if (locnames[format-1].equals("SpelloutLocalizations")) { - String lang = locale.getLanguage(); - for (int i = 0; i < NO_SPELLOUT_PARSE_LANGUAGES.length; i++) { - if (NO_SPELLOUT_PARSE_LANGUAGES[i].equals(lang)) { - noParse = true; - break; - } - } - } } private static final String[] rulenames = { @@ -1195,12 +1179,6 @@ public class RuleBasedNumberFormat extends NumberFormat { */ public Number parse(String text, ParsePosition parsePosition) { - //TODO: We need a real fix. See #6895 / #6896 - if (noParse) { - // skip parsing - return Long.valueOf(0); - } - // parsePosition tells us where to start parsing. We copy the // text in the string from here to the end inro a new string, // and create a new ParsePosition and result variable to use @@ -1219,7 +1197,7 @@ public class RuleBasedNumberFormat extends NumberFormat { // one consumes the most characters: that's the one that determines // the result we return for (int i = ruleSets.length - 1; i >= 0; i--) { - // skip private rule sets + // skip private or unparseable rule sets if (!ruleSets[i].isPublic() || !ruleSets[i].isParseable()) { continue; } diff --git a/icu4j/main/shared/data/icudata.jar b/icu4j/main/shared/data/icudata.jar index 77e7465d10c..4be07a1c444 100755 --- a/icu4j/main/shared/data/icudata.jar +++ b/icu4j/main/shared/data/icudata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a0ebb8aca35e3abc24835d6e9ca6229a86d314d81f2ffb2a5932a50d04afe0f4 -size 7931116 +oid sha256:4c233e092196b9cde61b61883025b58d1c60b8b6a5a89547468a38d7c4b88631 +size 7931207 diff --git a/icu4j/main/shared/data/icutzdata.jar b/icu4j/main/shared/data/icutzdata.jar index 9fc03aee7c4..e2da07ddb95 100755 --- a/icu4j/main/shared/data/icutzdata.jar +++ b/icu4j/main/shared/data/icutzdata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0082e2ceb617263b0e2d5badddecabe7c43034a3d3fc23b0c6c1eb1ed792376e -size 92697 +oid sha256:9ff10bd2029ec6b44be9ebd8e21bd66812446fde8e84ddd5c4f8d06c048a86e4 +size 92708 -- 2.40.0