javacommons/utils/javasrc/com/nokia/mj/impl/utils/Formatter.java
changeset 56 abc41079b313
parent 23 98ccebc37403
child 67 63b81d807542
--- a/javacommons/utils/javasrc/com/nokia/mj/impl/utils/Formatter.java	Fri Jul 09 16:35:45 2010 +0300
+++ b/javacommons/utils/javasrc/com/nokia/mj/impl/utils/Formatter.java	Fri Jul 23 12:27:20 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -28,6 +28,7 @@
  * <UL>
  * <LI>%nU - String in position n
  * <LI>%U - Next string
+ * <LI>%Ln - Integer in position n
  * <LI>%nN - Integer in position n
  * <LI>%N - Next integer
  * <LI>%nC - Character in position n
@@ -60,7 +61,7 @@
     private String replaced;
 
     /** Next replacement index */
-    private int nextIndex = 0;
+    private int nextIndex = (ResourceLoader.getLocaleIdQt() == null? 0: 1);
 
     /*** ----------------------------- PUBLIC ------------------------------ */
 
@@ -69,7 +70,7 @@
      *
      * @param pattern formatter pattern
      */
-    public Formatter(String aPattern)
+    Formatter(String aPattern)
     {
         pattern = aPattern;
         replaced = aPattern;
@@ -90,11 +91,12 @@
                 replace("%U", string))
         {
             nextIndex++;
-
         }
         else
         {
-            Logger.WLOG(Logger.EUtils, "String replacement failed");
+            Logger.WLOG(Logger.EUtils,
+                        "String replacement failed on parameter " +
+                        nextIndex + ": " + pattern);
         }
         return this;
     }
@@ -110,8 +112,9 @@
     {
         String localisedNumber = _formatInteger(number);
 
-        // Try to replace with patterns %nN, %n, %N
-        if (replace("%" + nextIndex + "N", localisedNumber) ||
+        // Try to replace with patterns %Ln, %nN, %n, %N
+        if (replace("%" + "L" + nextIndex, localisedNumber) ||
+                replace("%" + nextIndex + "N", localisedNumber) ||
                 replace("%" + nextIndex, localisedNumber) ||
                 replace("%N", localisedNumber))
         {
@@ -120,7 +123,9 @@
         }
         else
         {
-            Logger.WLOG(Logger.EUtils, "Integer replacement failed");
+            Logger.WLOG(Logger.EUtils,
+                        "Integer replacement failed on parameter " +
+                        nextIndex + ": " + pattern);
         }
         return this;
     }
@@ -146,7 +151,9 @@
         }
         else
         {
-            Logger.WLOG(Logger.EUtils, "Character replacement failed");
+            Logger.WLOG(Logger.EUtils,
+                        "Character replacement failed on parameter " +
+                        nextIndex + ": " + pattern);
         }
         return this;
     }
@@ -208,7 +215,7 @@
 
         // Reset for next usage
         replaced = pattern;
-        nextIndex = 0;
+        nextIndex = (ResourceLoader.getLocaleIdQt() == null? 0: 1);
 
         return result;
     }
@@ -260,6 +267,18 @@
         }
         return toString();
     }
+    /**
+     * Applies convertion from european digits into arabic-indic digits 
+     * based on existing language settings
+     *
+     * @param str String which might contain european digits
+     * @return A string identical with the provided string but with the 
+     *         european digits (if any) converted to arabic-indic digits
+     */
+    public static String formatDigits(String str)
+    {
+        return _formatDigits(str);
+    }
 
     /*** ----------------------------- PRIVATE ---------------------------- */
 
@@ -358,4 +377,14 @@
      *
      */
     private native String _formatDate(long timeInMilliSecs);
+
+    /**
+     * Applies convertion from european digits into arabic-indic digits
+     * based on existing language settings
+     *
+     * @param str String which might contain european digits
+     * @return A string identical with the provided string but with the 
+     *         european digits (if any) converted to arabic-indic digits
+     */
+    private static native String _formatDigits(String str);
 }