Index: chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java |
index 0bb0e59edf274bc3539621b135702dbf9c8090a1..693bc0344b742c9794ad17fe36721f4bc8b314cb 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java |
@@ -24,12 +24,25 @@ public class CurrencyStringFormatter { |
// Max currency code length. Maximum length of currency code can be at most 2048. |
private static final int MAX_CURRENCY_CODE_LEN = 2048; |
+ // Currency code exceeding 6 chars will be ellipsized during formatting for display. |
+ private static final int MAX_CURRENCY_CHARS = 6; |
+ |
+ // Unicode character for ellipsis. |
+ private static final String ELLIPSIS = "\u2026"; |
+ |
// Formatting constants. |
private static final int DIGIT_GROUPING_SIZE = 3; |
private final Pattern mAmountValuePattern; |
/** |
+ * The currency formatted for display. Currency can be any string of at most |
+ * 2048 characters.Currency code more than 6 character is formatted to first |
+ * 5 characters and ellipsis. |
+ */ |
+ public final String mFormattedCurrencyCode; |
+ |
+ /** |
* The symbol for the currency specified on the bill. For example, the symbol for "USD" is "$". |
*/ |
private final String mCurrencySymbol; |
@@ -66,6 +79,10 @@ public class CurrencyStringFormatter { |
mAmountValuePattern = Pattern.compile(AMOUNT_VALUE_PATTERN); |
+ mFormattedCurrencyCode = currencyCode.length() <= MAX_CURRENCY_CHARS |
+ ? currencyCode |
+ : currencyCode.substring(0, MAX_CURRENCY_CHARS - 1) + ELLIPSIS; |
gone
2016/09/06 17:20:32
Given that you're just tacking on an ellipsis, wil
pals
2016/09/08 04:12:14
I guess RTL rendering is taken care by view. I hav
|
+ |
String currencySymbol; |
int defaultFractionDigits; |
try { |
@@ -121,6 +138,11 @@ public class CurrencyStringFormatter { |
return amountCurrencyCode != null && amountCurrencyCode.length() <= MAX_CURRENCY_CODE_LEN; |
} |
+ /** @return The currency code formatted for display. */ |
+ public String getFormattedCurrencyCode() { |
+ return mFormattedCurrencyCode; |
+ } |
+ |
/** |
* Formats the currency string for display. Does not parse the string into a number, because it |
* might be too large. The number is formatted for the current locale and follows the symbol of |