harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Yu" <junjie0...@gmail.com>
Subject [classlib][text] ChoiceFormat(String) pattern parser differs from RI
Date Tue, 22 Apr 2008 03:00:21 GMT
Hi, all,
I looked at this JIRA[1]. As the reporter said, Harmony and RI have
different pattern parsers implementations
 of ChoiceFormat class. Since Spec doesn't have any rules for pattern except
a single example
"-1#is negative| 0#is zero or fraction | 1#is one |1.0<is 1+ |2#is two |2<is
more than 2."
So we have some differences in pattern parsing.
Test
---------------------------------------------------------------------------------------

import java.text.*;

public class bug9411 {
    public static void main(String[] args) {
      try {
          System.out.println(new ChoiceFormat("2#ok #ab").toPattern());
      } catch (Exception e) {
           e.printStackTrace();
      }
      try {
        System.out.println(new ChoiceFormat("2#ok <ab").toPattern());
      } catch (Exception e) {
         e.printStackTrace();
      }
    }
}

Output ---------------------------------------------------------------------

RI
java.lang.IllegalArgumentException
                      at
java.text.ChoiceFormat.applyPattern(ChoiceFormat.java:197)
                      at
java.text.ChoiceFormat.<init>(ChoiceFormat.java:294)
                      at bug9411.main(bug9411.java:12)
java.lang.IllegalArgumentException
                      at
java.text.ChoiceFormat.applyPattern(ChoiceFormat.java:197)
                      at
java.text.ChoiceFormat.<init>(ChoiceFormat.java:294)
                      at bug9411.main(bug9411.java:17)
Harmony
2.0#ok #ab
2.0#ok <ab

  From the output, RI treats "#" and "<" as reserved symbols. So it is
illegal in RI that reserved symbols are used in formats
directly. But in Harmony, these symbols are not reserved. It is legal in
Harmony to use them directly. I agree with the reporter's
view point that symbols "|", "#" and "<" should be reserved as pattern
control symbols because of their influence on pattern parse algorithm.
If user wants to use such symbols in formats, we'd better put them in quotes
to avoid misunderstandings. And according to my regression
test cases, RI behaves just like what I said. Now that spec doesn't have
specific rules about it, I think we should follow RI's behavior.
I've submitted my patch[1]. Any objection? If no, I will ask classlib
commiter to apply it: )

[1] https://issues.apache.org/jira/browse/HARMONY-1110

-- 
Best Regards,
Jim Yu (虞俊杰)

China Software Development Lab, IBM
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message