Index: java/text/AttributedStringIterator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/AttributedStringIterator.java,v retrieving revision 1.5 diff -u -r1.5 AttributedStringIterator.java --- java/text/AttributedStringIterator.java 28 Feb 2004 13:18:19 -0000 1.5 +++ java/text/AttributedStringIterator.java 20 Apr 2004 21:03:36 -0000 @@ -221,39 +221,28 @@ public synchronized int getRunLimit(Set attribute_set) { - int orig_index = ci.getIndex(); - int run_limit; + boolean hit = false; + int runLimit = ci.getEndIndex (); + int pos = ci.getIndex (); - do + for (int i = 0; i < attribs.length; ++i) { - run_limit = ci.getIndex(); - - Map attribute_map = getAttributes(); - - boolean found = false; - Iterator iter = attribute_set.iterator(); - while(iter.hasNext()) - if (!attribute_map.containsKey(iter.next())) - { - found = true; - break; - } - - if (found) - break; + if (pos >= attribs[i].begin_index && + pos <= attribs[i].end_index) + { + Iterator iter = attribute_set.iterator(); + while(iter.hasNext()) + if (attribs[i].attribs.containsKey(iter.next())) + { + hit = true; + runLimit = Math.min(runLimit, attribs[i].end_index); + } + } } - while (ci.next() != CharacterIterator.DONE); - - boolean hit_end = (ci.previous() == CharacterIterator.DONE); - - ci.setIndex(orig_index); - - if (run_limit == orig_index) - return(-1); // No characters match the given attributes -// else if (!hit_end) -// --run_limit; - - return(run_limit); + if (hit) + return runLimit; + else + return -1; } /*************************************************************************/ @@ -281,35 +270,28 @@ public int getRunStart(Set attribute_set) { - int orig_index = ci.getIndex(); - int run_start; + boolean hit = false; + int runBegin = 0; + int pos = ci.getIndex (); - do + for (int i = 0; i < attribs.length; ++i) { - run_start = ci.getIndex(); - - Map attribute_map = getAttributes(); - - Iterator iter = attribute_set.iterator(); - while(iter.hasNext()) - if (!attribute_map.containsKey(iter.next())) - break; - - if (iter.hasNext()) - break; + if (pos >= attribs[i].begin_index && + pos <= attribs[i].end_index) + { + Iterator iter = attribute_set.iterator(); + while(iter.hasNext()) + if (attribs[i].attribs.containsKey(iter.next())) + { + hit = true; + runBegin = Math.max(runBegin, attribs[i].begin_index); + } + } } - while (ci.previous() != CharacterIterator.DONE); - - boolean hit_beginning = (ci.previous() == CharacterIterator.DONE); - - ci.setIndex(orig_index); - - if (run_start == orig_index) - return(-1); // No characters match the given attributes - else if (!hit_beginning) - ++run_start; - - return(run_start); + if (hit) + return runBegin; + else + return -1; } /*************************************************************************/ Index: java/text/AttributedString.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/AttributedString.java,v retrieving revision 1.5 diff -u -r1.5 AttributedString.java --- java/text/AttributedString.java 8 Mar 2004 23:27:04 -0000 1.5 +++ java/text/AttributedString.java 20 Apr 2004 21:03:36 -0000 @@ -38,6 +38,7 @@ package java.text; +import java.util.Arrays; import java.util.Iterator; import java.util.HashMap; import java.util.Hashtable; @@ -219,26 +220,7 @@ // Get the valid attribute list Set all_attribs = aci.getAllAttributeKeys(); if (attributes != null) - { - Set valid_attribs = new HashSet(); - Iterator iter = all_attribs.iterator(); - while (iter.hasNext()) - { - Object obj = iter.next(); - - int i; - for (i = 0; i < attributes.length; i++) - if (obj.equals(attributes[0])) - break; - - if (i == attributes.length) - continue; - - valid_attribs.add(obj); - } - - all_attribs = valid_attribs; - } + all_attribs.retainAll(Arrays.asList(attributes)); // Loop through and extract the attributes char c = aci.setIndex(begin_index); @@ -320,7 +302,7 @@ public void addAttribute(AttributedCharacterIterator.Attribute attrib, Object value) { - addAttribute(attrib, value, 0, sci.getEndIndex() - 1); + addAttribute(attrib, value, 0, sci.getEndIndex()); } /*************************************************************************/ @@ -389,8 +371,7 @@ public AttributedCharacterIterator getIterator() { - return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex() - 1, - null)); + return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex(), null)); } /*************************************************************************/ @@ -409,7 +390,7 @@ public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes) { - return(getIterator(attributes, 0, sci.getEndIndex() - 1)); + return(getIterator(attributes, 0, sci.getEndIndex())); } /*************************************************************************/