diff options
Diffstat (limited to 'libjava/java/text')
-rw-r--r-- | libjava/java/text/RuleBasedCollator.java | 11 | ||||
-rw-r--r-- | libjava/java/text/StringCharacterIterator.java | 165 |
2 files changed, 100 insertions, 76 deletions
diff --git a/libjava/java/text/RuleBasedCollator.java b/libjava/java/text/RuleBasedCollator.java index 2fb667ef838..dde09572923 100644 --- a/libjava/java/text/RuleBasedCollator.java +++ b/libjava/java/text/RuleBasedCollator.java @@ -176,6 +176,17 @@ public class RuleBasedCollator extends Collator return new CollationElementIterator (expand.toString(), this); } + public CollationElementIterator getCollationElementIterator (CharacterIterator source) + { + StringBuffer expand = new StringBuffer (); + for (char c = source.first (); + c != CharacterIterator.DONE; + c = source.next ()) + decomposeCharacter (c, expand); + + return new CollationElementIterator (expand.toString(), this); + } + public CollationKey getCollationKey (String source) { return new CollationKey (getCollationElementIterator (source), source, diff --git a/libjava/java/text/StringCharacterIterator.java b/libjava/java/text/StringCharacterIterator.java index dc02ce86282..487b09c8220 100644 --- a/libjava/java/text/StringCharacterIterator.java +++ b/libjava/java/text/StringCharacterIterator.java @@ -22,108 +22,121 @@ package java.text; public final class StringCharacterIterator implements CharacterIterator { public Object clone () - { - return (Object) new StringCharacterIterator (text, begin, end, pos); - } + { + return (Object) new StringCharacterIterator (text, begin, end, pos); + } public char current () - { - // This follows JDK 1.2 semantics and not 1.1 semantics. - // In 1.1 we would throw an exception if begin==end. - return (pos < end) ? text.charAt(pos) : CharacterIterator.DONE; - } + { + // This follows JDK 1.2 semantics and not 1.1 semantics. + // In 1.1 we would throw an exception if begin==end. + return (pos < end) ? text.charAt(pos) : CharacterIterator.DONE; + } public boolean equals (Object obj) - { - if (! (obj instanceof StringCharacterIterator)) - return false; - StringCharacterIterator sci = (StringCharacterIterator) obj; - // The spec says "the same text". We take this to mean equals, - // not ==. - return (pos == sci.pos - && begin == sci.begin - && end == sci.end - && text.equals(sci.text)); - } + { + if (! (obj instanceof StringCharacterIterator)) + return false; + StringCharacterIterator sci = (StringCharacterIterator) obj; + // The spec says "the same text". We take this to mean equals, + // not ==. + return (pos == sci.pos + && begin == sci.begin + && end == sci.end + && text.equals(sci.text)); + } public char first () - { - pos = begin; - return current (); - } + { + pos = begin; + return current (); + } public int getBeginIndex () - { - return begin; - } + { + return begin; + } public int getEndIndex () - { - return end; - } + { + return end; + } public int getIndex () - { - return pos; - } + { + return pos; + } public int hashCode () - { - // FIXME: this is a terrible hash code. Find a better one. - return text.hashCode() + pos + begin + end; - } + { + // FIXME: this is a terrible hash code. Find a better one. + return text.hashCode() + pos + begin + end; + } public char last () - { - pos = end; - return current (); - } + { + pos = end; + return current (); + } public char next () - { - if (pos == end) - return CharacterIterator.DONE; - ++pos; - return current (); - } + { + if (pos == end) + return CharacterIterator.DONE; + ++pos; + return current (); + } public char previous () - { - if (pos == begin) - return CharacterIterator.DONE; - --pos; - return current (); - } + { + if (pos == begin) + return CharacterIterator.DONE; + --pos; + return current (); + } public char setIndex (int idx) - { - // In 1.1 we would throw an error if `idx == end'. - if (idx < begin || idx > end) - throw new IllegalArgumentException (); - pos = idx; - return current (); - } + { + // In 1.1 we would throw an error if `idx == end'. + if (idx < begin || idx > end) + throw new IllegalArgumentException (); + pos = idx; + return current (); + } public StringCharacterIterator (String text) - { - this (text, 0, text.length(), 0); - } + { + this (text, 0, text.length(), 0); + } + public StringCharacterIterator (String text, int pos) - { - this (text, 0, text.length(), pos); - } + { + this (text, 0, text.length(), pos); + } + public StringCharacterIterator (String text, int begin, int end, int pos) - { - if (begin < 0 || begin > end || end > text.length() - // In 1.1 we would also throw if `pos == end'. - || pos < begin || pos > end) - throw new IllegalArgumentException (); - - this.text = text; - this.begin = begin; - this.end = end; - this.pos = pos; - } + { + if (begin < 0 || begin > end || end > text.length() + // In 1.1 we would also throw if `pos == end'. + || pos < begin || pos > end) + throw new IllegalArgumentException (); + + this.text = text; + this.begin = begin; + this.end = end; + this.pos = pos; + } + + // The online 1.2 docs say that this is "package visible" in the + // method description, but they also say it is public. We choose + // the latter for compatibility with the actual implementation. + public void setText (String text) + { + this.text = text; + this.begin = 0; + this.end = text.length (); + this.pos = 0; + } // String to iterate over. private String text; |