ICU-1776 ensure extra semicolons do not affect rule parse in java

X-SVN-Rev: 11546
This commit is contained in:
Doug Felt 2003-04-15 14:58:17 +00:00
parent 883a9b9000
commit 0a866746c1
2 changed files with 59 additions and 8 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/RbnfTest.java,v $
* $Date: 2002/12/18 21:20:52 $
* $Revision: 1.15 $
* $Date: 2003/04/15 14:58:16 $
* $Revision: 1.16 $
*
*****************************************************************************************
*/
@ -590,7 +590,7 @@ public class RbnfTest extends TestFmwk {
}
/**
* Perform a simple spot check on the German spellout rules
* Perform a simple spot check on the Thai spellout rules
*/
public void TestThaiSpellout() {
RuleBasedNumberFormat formatter
@ -729,6 +729,51 @@ public class RbnfTest extends TestFmwk {
logln("big dec: " + buf.toString());
}
public void TestTrailingSemicolon() {
String thaiRules =
"%default:\n" +
" -x: \u0e25\u0e1a>>;\n" +
" x.x: <<\u0e08\u0e38\u0e14>>>;\n" +
" \u0e28\u0e39\u0e19\u0e22\u0e4c; \u0e2b\u0e19\u0e36\u0e48\u0e07; \u0e2a\u0e2d\u0e07; \u0e2a\u0e32\u0e21;\n" +
" \u0e2a\u0e35\u0e48; \u0e2b\u0e49\u0e32; \u0e2b\u0e01; \u0e40\u0e08\u0e47\u0e14; \u0e41\u0e1b\u0e14;\n" +
" \u0e40\u0e01\u0e49\u0e32; \u0e2a\u0e34\u0e1a; \u0e2a\u0e34\u0e1a\u0e40\u0e2d\u0e47\u0e14;\n" +
" \u0e2a\u0e34\u0e1a\u0e2a\u0e2d\u0e07; \u0e2a\u0e34\u0e1a\u0e2a\u0e32\u0e21;\n" +
" \u0e2a\u0e34\u0e1a\u0e2a\u0e35\u0e48; \u0e2a\u0e34\u0e1a\u0e2b\u0e49\u0e32;\n" +
" \u0e2a\u0e34\u0e1a\u0e2b\u0e01; \u0e2a\u0e34\u0e1a\u0e40\u0e08\u0e47\u0e14;\n" +
" \u0e2a\u0e34\u0e1a\u0e41\u0e1b\u0e14; \u0e2a\u0e34\u0e1a\u0e40\u0e01\u0e49\u0e32;\n" +
" 20: \u0e22\u0e35\u0e48\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 30: \u0e2a\u0e32\u0e21\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 40: \u0e2a\u0e35\u0e48\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 50: \u0e2b\u0e49\u0e32\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 60: \u0e2b\u0e01\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 70: \u0e40\u0e08\u0e47\u0e14\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 80: \u0e41\u0e1b\u0e14\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 90: \u0e40\u0e01\u0e49\u0e32\u0e2a\u0e34\u0e1a[>%%alt-ones>];\n" +
" 100: <<\u0e23\u0e49\u0e2d\u0e22[>>];\n" +
" 1000: <<\u0e1e\u0e31\u0e19[>>];\n" +
" 10000: <<\u0e2b\u0e21\u0e37\u0e48\u0e19[>>];\n" +
" 100000: <<\u0e41\u0e2a\u0e19[>>];\n" +
" 1,000,000: <<\u0e25\u0e49\u0e32\u0e19[>>];\n" +
" 1,000,000,000: <<\u0e1e\u0e31\u0e19\u0e25\u0e49\u0e32\u0e19[>>];\n" +
" 1,000,000,000,000: <<\u0e25\u0e49\u0e32\u0e19\u0e25\u0e49\u0e32\u0e19[>>];\n" +
" 1,000,000,000,000,000: =#,##0=;\n" +
"%%alt-ones:\n" +
" \u0e28\u0e39\u0e19\u0e22\u0e4c;\n" +
" \u0e40\u0e2d\u0e47\u0e14;\n" +
" =%default=;\n ; ;; ";
RuleBasedNumberFormat formatter
= new RuleBasedNumberFormat(thaiRules, new Locale("th", "TH", ""));
String[][] testData = {
{ "0", "\u0e28\u0e39\u0e19\u0e22\u0e4c" },
{ "1", "\u0e2b\u0e19\u0e36\u0e48\u0e07" },
{ "123.45", "\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e23\u0e49\u0e2d\u0e22\u0e22\u0e35\u0e48\u0e2a\u0e34\u0e1a\u0e2a\u0e32\u0e21\u0e08\u0e38\u0e14\u0e2a\u0e35\u0e48\u0e2b\u0e49\u0e32" }
};
doTest(formatter, testData, true);
}
void doTest(RuleBasedNumberFormat formatter, String[][] testData,
boolean testParsing) {
NumberFormat decFmt = NumberFormat.getInstance(Locale.US);

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java,v $
* $Date: 2002/12/05 01:22:20 $
* $Revision: 1.11 $
* $Date: 2003/04/15 14:58:17 $
* $Revision: 1.12 $
*
*****************************************************************************************
*/
@ -472,7 +472,7 @@ import java.util.Vector;
* using these features.</p>
*
* @author Richard Gillam
* $RCSfile: RuleBasedNumberFormat.java,v $ $Revision: 1.11 $ $Date: 2002/12/05 01:22:20 $
* $RCSfile: RuleBasedNumberFormat.java,v $ $Revision: 1.12 $ $Date: 2003/04/15 14:58:17 $
* @see NumberFormat
* @see DecimalFormat
* @stable ICU 2.0
@ -1207,7 +1207,7 @@ public final class RuleBasedNumberFormat extends NumberFormat {
*/
private String stripWhitespace(String description) {
// since we don't have a method that deletes characters (why?!!)
// create a nwe StringBuffer to copy the text into
// create a new StringBuffer to copy the text into
StringBuffer result = new StringBuffer();
// iterate through the characters...
@ -1219,7 +1219,13 @@ public final class RuleBasedNumberFormat extends NumberFormat {
++start;
}
// locate the next semicolon in the text and copyt he text from
//if the first non-whitespace character is semicolon, skip it and continue
if (start < description.length() && description.charAt(start) == ';') {
start += 1;
continue;
}
// locate the next semicolon in the text and copy the text from
// our current position up to that semicolon into the result
int p;
p = description.indexOf(';', start);