hi,

this fixes some arithmetic and semantic errors with attributed
strings.

-graydon

2003-11-18  Graydon Hoare  <[EMAIL PROTECTED]>

        * java/text/AttributedString.java: Fix arithmetic.
        * java/text/AttributedStringIterator.java: Likewise.

--- java/text/AttributedString.java	22 Jan 2002 22:27:01 -0000	1.4
+++ java/text/AttributedString.java	17 Nov 2003 17:38:59 -0000
@@ -319,7 +319,7 @@
 public void
 addAttribute(AttributedCharacterIterator.Attribute attrib, Object value)
 {
-  addAttribute(attrib, value, 0, sci.getEndIndex() - 1);
+  addAttribute(attrib, value, 0, sci.getEndIndex());
 }
 
 /*************************************************************************/
@@ -388,8 +388,7 @@
 public AttributedCharacterIterator
 getIterator()
 {
-  return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex() - 1,
-                                      null));
+  return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex(), null));
 }
 
 /*************************************************************************/
@@ -408,8 +407,8 @@
 public AttributedCharacterIterator
 getIterator(AttributedCharacterIterator.Attribute[] attributes)
 {
-  return(getIterator(attributes, 0, sci.getEndIndex() - 1));
+  return(getIterator(attributes, 0, sci.getEndIndex()));
 }
 
 /*************************************************************************/
--- java/text/AttributedStringIterator.java	22 Jan 2002 22:27:01 -0000	1.4
+++ java/text/AttributedStringIterator.java	17 Nov 2003 17:38:59 -0000
@@ -217,39 +217,28 @@
 public synchronized int
 getRunLimit(Set attribute_set)
 {
-  int orig_index = ci.getIndex();
-  int run_limit;
-
-  do  
-    {
-      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;
-    }
-  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); 
+    boolean hit = false;
+    int runLimit = ci.getEndIndex ();
+    int pos = ci.getIndex ();
+
+    for (int i = 0; i < attribs.length; ++i)
+	{
+	    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);
+			    }
+		}
+	}
+    if (hit)
+	return runLimit;
+    else
+	return -1;
 }
 
 /*************************************************************************/
@@ -277,35 +266,28 @@
 public int
 getRunStart(Set attribute_set)
 {
-  int orig_index = ci.getIndex();
-  int run_start;
-
-  do  
-    {
-      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;
-    }
-  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); 
+    boolean hit = false;
+    int runBegin = 0;
+    int pos = ci.getIndex ();
+
+    for (int i = 0; i < attribs.length; ++i)
+	{
+	    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);
+			    }
+		}
+	}
+    if (hit)
+	return runBegin;
+    else
+	return -1;
 }
 
 /*************************************************************************/
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to