summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--java/text/AttributedString.java29
-rw-r--r--java/text/AttributedStringIterator.java94
3 files changed, 53 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index b951dd768..7e329bf5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,13 @@
-2004-04-20 Michael Koch <konqueror@gmx.de>
-
- * java/lang/SecurityManager.java
- (checkAWTEventQueueAccess): Implemented.
+2004-04-20 Graydon Hoare <graydon@redhat.com>
+
+ * java/text/AttributedString.java
+ (addAttribute): Fix off-by-one.
+ (getIterator): Likewise.
+ * java/text/AttributedStringIterator.java
+ (getRunLimit): Correct logic.
+ (getRunStart): Likewise.
+ (getAttribute): Fix inequality.
+ (getAttributes): Likewise.
2004-04-20 Michael Koch <konqueror@gmx.de>
diff --git a/java/text/AttributedString.java b/java/text/AttributedString.java
index a8eede813..46cbf92d5 100644
--- a/java/text/AttributedString.java
+++ b/java/text/AttributedString.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.text;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Hashtable;
@@ -219,26 +220,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
// 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 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
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 @@ addAttributes(Map attributes, int begin_index, int end_index)
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 @@ getIterator()
public AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[] attributes)
{
- return(getIterator(attributes, 0, sci.getEndIndex() - 1));
+ return(getIterator(attributes, 0, sci.getEndIndex()));
}
/*************************************************************************/
diff --git a/java/text/AttributedStringIterator.java b/java/text/AttributedStringIterator.java
index 77c598170..98204574c 100644
--- a/java/text/AttributedStringIterator.java
+++ b/java/text/AttributedStringIterator.java
@@ -221,39 +221,28 @@ getRunLimit(AttributedCharacterIterator.Attribute attrib)
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 @@ getRunStart(AttributedCharacterIterator.Attribute attrib)
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;
}
/*************************************************************************/