[kaffe] CVS kaffe (guilhem): Some fixes for java.text

Kaffe CVS cvs-commits at kaffe.org
Tue Mar 30 08:54:03 PST 2004


PatchSet 4600 
Date: 2004/03/30 16:05:33
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Some fixes for java.text

        * libraries/javalib/java/text/CollationElementIterator.java:
        Fixed an infinite loop.

        Checked in a fix from GCJ developers.

        2004-03-23  Graydon Hoare  <graydon at 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-03-26  Peter Moon <peterm at miraculum.com>

                * java/text/NumberFormat.java: Fix spelling of setCurrency
                method

Members: 
	ChangeLog:1.2177->1.2178 
	libraries/javalib/java/text/AttributedString.java:1.4->1.5 
	libraries/javalib/java/text/AttributedStringIterator.java:1.3->1.4 
	libraries/javalib/java/text/CollationElementIterator.java:1.13->1.14 
	libraries/javalib/java/text/NumberFormat.java:1.20->1.21 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2177 kaffe/ChangeLog:1.2178
--- kaffe/ChangeLog:1.2177	Tue Mar 30 15:15:19 2004
+++ kaffe/ChangeLog	Tue Mar 30 16:05:33 2004
@@ -1,3 +1,32 @@
+2004-03-30  Guilhem Lavaux <guilhem at kaffe.org>
+
+	* libraries/javalib/java/text/CollationElementIterator.java:
+	Fixed an infinite loop.
+
+2004-03-30  Guilhem Lavaux <guilhem at kaffe.org>
+
+	Checked in a fix from GCJ developers.
+
+	2004-03-23  Graydon Hoare  <graydon at 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-03-30  Guilhem Lavaux <guilhem at kaffe.org>
+
+	Checked in a fix from GCJ developers.
+
+	2004-03-26  Peter Moon <peterm at miraculum.com>
+
+		* java/text/NumberFormat.java: Fix spelling of setCurrency
+		method
+
 2004-03-30  Dalibor Topic <robilad at kaffe.org>
 
 	* libraries/clib/awt/X/toolkit.h:
Index: kaffe/libraries/javalib/java/text/AttributedString.java
diff -u kaffe/libraries/javalib/java/text/AttributedString.java:1.4 kaffe/libraries/javalib/java/text/AttributedString.java:1.5
--- kaffe/libraries/javalib/java/text/AttributedString.java:1.4	Mon Mar 22 11:25:04 2004
+++ kaffe/libraries/javalib/java/text/AttributedString.java	Tue Mar 30 16:05:38 2004
@@ -38,6 +38,7 @@
 
 package java.text;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -218,27 +219,8 @@
 
   // 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;
-    } 
+   if (attributes != null)
+     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,8 @@
 public AttributedCharacterIterator
 getIterator()
 {
-  return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex() - 1,
-                                      null));
+  return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex(),
+				      null));
 }
 
 /*************************************************************************/
@@ -409,7 +391,7 @@
 public AttributedCharacterIterator
 getIterator(AttributedCharacterIterator.Attribute[] attributes)
 {
-  return(getIterator(attributes, 0, sci.getEndIndex() - 1));
+  return(getIterator(attributes, 0, sci.getEndIndex()));
 }
 
 /*************************************************************************/
Index: kaffe/libraries/javalib/java/text/AttributedStringIterator.java
diff -u kaffe/libraries/javalib/java/text/AttributedStringIterator.java:1.3 kaffe/libraries/javalib/java/text/AttributedStringIterator.java:1.4
--- kaffe/libraries/javalib/java/text/AttributedStringIterator.java:1.3	Mon Mar 22 11:25:04 2004
+++ kaffe/libraries/javalib/java/text/AttributedStringIterator.java	Tue Mar 30 16:05:40 2004
@@ -221,39 +221,32 @@
 public synchronized int
 getRunLimit(Set attribute_set)
 {
-  int orig_index = ci.getIndex();
-  int run_limit;
-
-  do  
+  boolean hit = false;
+  int runLimit = ci.getEndIndex ();
+  int pos = ci.getIndex ();
+ 
+  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)
+	{
+	  Map attribute_map = getAttributes();
+	  
+	  boolean found = false;
+	  Iterator iter = attribute_set.iterator();
+	  while(iter.hasNext()) 
+	    if (!attribute_map.containsKey(iter.next()))
+	      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 +274,28 @@
 public int
 getRunStart(Set attribute_set)
 {
-  int orig_index = ci.getIndex();
-  int run_start;
-
-  do  
+  boolean hit = false;
+  int runBegin = 0;
+  int pos = ci.getIndex ();
+  
+  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: kaffe/libraries/javalib/java/text/CollationElementIterator.java
diff -u kaffe/libraries/javalib/java/text/CollationElementIterator.java:1.13 kaffe/libraries/javalib/java/text/CollationElementIterator.java:1.14
--- kaffe/libraries/javalib/java/text/CollationElementIterator.java:1.13	Mon Mar 22 11:25:04 2004
+++ kaffe/libraries/javalib/java/text/CollationElementIterator.java	Tue Mar 30 16:05:40 2004
@@ -231,6 +231,7 @@
   public void setText(String text)
   {
     int idx = 0;
+    int alreadyExpanded = 0;
 
     this.text = text;
     this.index = 0;
@@ -254,6 +255,16 @@
 	      key_old = key;
 	    key = work_text.substring (idx, idx+p);
 	    object = collator.prefix_tree.get (key);
+	    if (object != null && idx < alreadyExpanded)
+	      {
+		RuleBasedCollator.CollationElement prefix = (RuleBasedCollator.CollationElement)object;
+		if (prefix.expansion != null && 
+		    prefix.expansion.startsWith(work_text.substring(0, idx)))
+		{
+		  object = null;
+		  key = key_old;
+		}
+	      }
 	    p++;
 	  }
 	while (idx+p <= work_text.length());
@@ -279,6 +290,7 @@
 	    work_text = prefix.expansion
 	      + work_text.substring (idx+prefix.key.length());
 	    idx = 0;
+	    alreadyExpanded = prefix.expansion.length();
 	    v.add (prefix);
 	  }
 	else
Index: kaffe/libraries/javalib/java/text/NumberFormat.java
diff -u kaffe/libraries/javalib/java/text/NumberFormat.java:1.20 kaffe/libraries/javalib/java/text/NumberFormat.java:1.21
--- kaffe/libraries/javalib/java/text/NumberFormat.java:1.20	Mon Mar 22 11:25:05 2004
+++ kaffe/libraries/javalib/java/text/NumberFormat.java	Tue Mar 30 16:05:40 2004
@@ -794,7 +794,7 @@
    *
    * @since 1.4
    */
-  public void setCurreny(Currency currency)
+  public void setCurrency(Currency currency)
   {
     if (currency == null)
       throw new NullPointerException("currency may not be null");




More information about the kaffe mailing list