--- a/javacommons/utils/javasrc/com/nokia/mj/impl/utils/Formatter.java Fri Sep 17 08:28:21 2010 +0300
+++ b/javacommons/utils/javasrc/com/nokia/mj/impl/utils/Formatter.java Mon Oct 04 00:10:53 2010 +0300
@@ -111,8 +111,10 @@
*/
public Formatter arg(String string)
{
- // Try to replace with patterns %nU,%n, %U
- if (replace("%" + nextIndex + "U", string) ||
+ // Try to replace with patterns %[N...N]n, %nU, %n, %U
+ String maxPattern = findMaxPattern();
+ if ((maxPattern != null && replace(maxPattern, string)) ||
+ replace("%" + nextIndex + "U", string) ||
replace("%" + nextIndex, string) ||
replace("%U", string))
{
@@ -138,8 +140,10 @@
{
String localisedNumber = _formatInteger(number);
- // Try to replace with patterns %Ln, %nN, %n, %N
- if (replace("%" + "L" + nextIndex, localisedNumber) ||
+ // Try to replace with patterns %[N...N]n, %Ln, %nN, %n, %N
+ String maxPattern = findMaxPattern();
+ if ((maxPattern != null && replace(maxPattern, localisedNumber)) ||
+ replace("%" + "L" + nextIndex, localisedNumber) ||
replace("%" + nextIndex + "N", localisedNumber) ||
replace("%" + nextIndex, localisedNumber) ||
replace("%N", localisedNumber))
@@ -167,7 +171,7 @@
{
String chString = new String(new char[] { ch });
- // Try to replace with patterns %nC,%n, %C
+ // Try to replace with patterns %nC, %n, %C
if (replace("%" + nextIndex + "C", chString) ||
replace("%" + nextIndex, chString) ||
replace("%C", chString))
@@ -372,6 +376,28 @@
return result;
}
+ /**
+ * Finds next %[N...N]n pattern from the replaced field.
+ * Returns found pattern, or null if no pattern was found.
+ */
+ private String findMaxPattern()
+ {
+ String result = null;
+ String startPattern = "%[";
+ String endPattern = "]" + nextIndex;
+ int startIndex = replaced.indexOf(startPattern);
+ if (startIndex >= 0)
+ {
+ int endIndex = replaced.indexOf(endPattern, startIndex);
+ if (endIndex >= 0)
+ {
+ result = replaced.substring(
+ startIndex, endIndex + endPattern.length());
+ }
+ }
+ return result;
+ }
+
/*** ----------------------------- NATIVE ----------------------------- */
/**