Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/CurrencyStringFormatter.java

Issue 2281913002: Currency code exceeding 6 chars will be ellipsized. (Closed)
Patch Set: Added comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698