Small DecimalFormat fix, other will follow if time permits, this is
needed to make the class 0.93 ready :).

2006-12-01  Mario Torre  <[EMAIL PROTECTED]>

        * java/text/DecimalFormat.java (formatInternal): move the formatting of
        fractional portion in a separate method.
        Also fixes the handling of decimal separator and its associated field.
        (handleFractionalPart): new method, needed to relax a bit
        formatInternal.

Mario

-- 
Lima Software, SO.PR.IND. s.r.l.
http://www.limasoftware.net/
pgp key: http://subkeys.pgp.net/

Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0
#P classpath
Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormat.java,v
retrieving revision 1.29
diff -u -r1.29 DecimalFormat.java
--- java/text/DecimalFormat.java	29 Nov 2006 16:51:13 -0000	1.29
+++ java/text/DecimalFormat.java	1 Dec 2006 22:22:17 -0000
@@ -1893,30 +1893,102 @@
     // add the INTEGER attribute
     addAttribute(Field.INTEGER, attributeStart, dest.length());
     
-    if (this.decimalSeparatorAlwaysShown ||
-        ((!isLong || this.useExponentialNotation)
-         && this.showDecimalSeparator &&
-         this.maximumFractionDigits > 0) ||
-         this.minimumFractionDigits > 0)
+    // ...update field position, if needed, and return...
+    if ((fieldPos.getField() == INTEGER_FIELD ||
+        fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER))
+      {
+        fieldPos.setBeginIndex(beginIndexInt);
+        fieldPos.setEndIndex(endIndexInt);
+      }
+    
+    handleFractionalPart(dest, fractPart, fieldPos, isLong);
+        
+    // and the exponent
+    if (this.useExponentialNotation)
       {
         attributeStart = dest.length();
         
+        dest.append(symbols.getExponential());
+        
+        addAttribute(Field.EXPONENT_SYMBOL, attributeStart, dest.length());
+        attributeStart = dest.length();
+        
+        if (exponent < 0)
+          {
+            dest.append(symbols.getMinusSign());
+            exponent = -exponent;
+            
+            addAttribute(Field.EXPONENT_SIGN, attributeStart, dest.length());
+          }
+        
+        attributeStart = dest.length();
+        
+        String exponentString = String.valueOf(exponent);
+        int exponentLength = exponentString.length();
+        
+        for (int i = 0; i < minExponentDigits - exponentLength; i++)
+          dest.append(symbols.getZeroDigit());
+        
+        for (int i = 0; i < exponentLength; ++i)
+          dest.append(exponentString.charAt(i));
+        
+        addAttribute(Field.EXPONENT, attributeStart, dest.length());
+      }
+ 
+    // now include the suffixes...
+    if (isNegative)
+      {
+        dest.append(negativeSuffix);
+      }
+    else
+      {
+        dest.append(positiveSuffix);
+      }
+  }
+
+  /**
+   * Add to the input buffer the result of formatting the fractional
+   * portion of the number.
+   * 
+   * @param dest
+   * @param fractPart
+   * @param fieldPos
+   * @param isLong
+   */
+  private void handleFractionalPart(StringBuffer dest, String fractPart,
+                                    FieldPosition fieldPos, boolean isLong)
+  {
+    int dotStart = 0;
+    int dotEnd = 0;
+    boolean addDecimal = false;
+    
+    if (this.decimalSeparatorAlwaysShown  ||
+         ((!isLong || this.useExponentialNotation) &&
+           this.showDecimalSeparator && this.maximumFractionDigits > 0) ||
+        this.minimumFractionDigits > 0)
+      {
+        dotStart = dest.length();
+        
         if (this.useCurrencySeparator)
           dest.append(symbols.getMonetaryDecimalSeparator());
         else
           dest.append(symbols.getDecimalSeparator());
         
-        // add the INTEGER attribute
-        addAttribute(Field.DECIMAL_SEPARATOR, attributeStart, dest.length());
+        dotEnd = dest.length();
+        addDecimal = true;
       }
     
     // now handle the fraction portion of the number
+    int fractStart = 0;
+    int fractEnd = 0;
+    boolean addFractional = false;
+    
     if ((!isLong || this.useExponentialNotation)
         && this.maximumFractionDigits > 0
         || this.minimumFractionDigits > 0)
       {
-        attributeStart = dest.length();
-        beginIndexFract = attributeStart;
+        fractStart = dest.length();
+        fractEnd = fractStart;
         
         int digits = this.minimumFractionDigits;
         
@@ -1939,83 +2011,41 @@
             if (fracts[i] != '0')
               allZeros = false;
           }
-             
+        
         if (!allZeros || (minimumFractionDigits > 0))
           {
             appendDigit(fractPart, dest, false);
-            endIndexFract = dest.length();
-            addAttribute(Field.FRACTION, attributeStart, endIndexFract);
+            fractEnd = dest.length();
+            
+            addDecimal = true;
+            addFractional = true;
           }
         else if (!this.decimalSeparatorAlwaysShown)
           {
             dest.deleteCharAt(dest.length() - 1);
+            addDecimal = false;
           }
         else
           {
-            System.out.println("ayeeeee!");
-            endIndexFract = dest.length();
-            addAttribute(Field.FRACTION, attributeStart, endIndexFract);
+            fractEnd = dest.length();
+            addFractional = true;
           }
       }
     
-    // and the exponent
-    if (this.useExponentialNotation)
-      {
-        attributeStart = dest.length();
-        
-        dest.append(symbols.getExponential());
-        
-        addAttribute(Field.EXPONENT_SYMBOL, attributeStart, dest.length());
-        attributeStart = dest.length();
-        
-        if (exponent < 0)
-          {
-            dest.append(symbols.getMinusSign());
-            exponent = -exponent;
-            
-            addAttribute(Field.EXPONENT_SIGN, attributeStart, dest.length());
-          }
-        
-        attributeStart = dest.length();
-        
-        String exponentString = String.valueOf(exponent);
-        int exponentLength = exponentString.length();
-        
-        for (int i = 0; i < minExponentDigits - exponentLength; i++)
-          dest.append(symbols.getZeroDigit());
-        
-        for (int i = 0; i < exponentLength; ++i)
-          dest.append(exponentString.charAt(i));
-        
-        addAttribute(Field.EXPONENT, attributeStart, dest.length());
-      }
- 
-    // now include the suffixes...
-    if (isNegative)
-      {
-        dest.append(negativeSuffix);
-      }
-    else
-      {
-        dest.append(positiveSuffix);
-      }
+    if (addDecimal)
+      addAttribute(Field.DECIMAL_SEPARATOR, dotStart, dotEnd);
     
-    // ...update field position, if needed, and return...
-    if ((fieldPos.getField() == INTEGER_FIELD ||
-        fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER))
-      {
-        fieldPos.setBeginIndex(beginIndexInt);
-        fieldPos.setEndIndex(endIndexInt);
-      }
+    if (addFractional)
+      addAttribute(Field.FRACTION, fractStart, fractEnd);
     
     if ((fieldPos.getField() == FRACTION_FIELD ||
         fieldPos.getFieldAttribute() == NumberFormat.Field.FRACTION))
       {
-        fieldPos.setBeginIndex(beginIndexFract);
-        fieldPos.setEndIndex(endIndexFract);
+        fieldPos.setBeginIndex(fractStart);
+        fieldPos.setEndIndex(fractEnd);
       }
   }
-
+  
   /**
    * Append to <code>dest</code>the give number of zeros.
    * Grouping is added if needed.

Attachment: signature.asc
Description: Questa รจ una parte del messaggio firmata digitalmente

Reply via email to