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..583a193dd9501d2ece8134caec15d294cba25b6b 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,6 +24,12 @@ 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; |
@@ -122,6 +128,23 @@ public class CurrencyStringFormatter { |
} |
/** |
+ * Formats the currency 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. |
+ * |
+ * @param currency The currency code to format. Should not be null. |
+ * @return The formatted currency code. |
+ */ |
+ public String formatCurrency(String currency) { |
please use gerrit instead
2016/09/02 17:30:55
/** @return The currency code formatted for displa
pals
2016/09/06 06:09:00
Done.
|
+ assert currency != null : "currency should not be null"; |
+ |
+ if (currency.length() <= MAX_CURRENCY_CHARS) { |
+ return currency; |
+ } |
+ |
+ return currency.substring(0, MAX_CURRENCY_CHARS - 1) + ELLIPSIS; |
+ } |
+ |
+ /** |
* 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 |
* the currency code. |