summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-10-09 18:08:52 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-10-09 18:08:52 +0000
commita96d6871503966e8589ee8d929acc68ee1e4d59c (patch)
treee5d27cb9161dc540138f8c69088f6d0589a1edc0
parent7d7c48079d8ac61068cac7caf0072fa6c1fbe0a2 (diff)
parenta68116c0d8ff9cd517d6b765bf2b8930ed9a3e12 (diff)
downloadlibcore-a96d6871503966e8589ee8d929acc68ee1e4d59c.zip
libcore-a96d6871503966e8589ee8d929acc68ee1e4d59c.tar.gz
libcore-a96d6871503966e8589ee8d929acc68ee1e4d59c.tar.bz2
Merge "Support DecimalFormatSymbols' percent symbol being a string."
-rw-r--r--luni/src/main/java/java/text/DecimalFormatSymbols.java16
-rw-r--r--luni/src/main/java/libcore/icu/LocaleData.java2
-rw-r--r--luni/src/main/java/libcore/icu/NativeDecimalFormat.java8
-rw-r--r--luni/src/main/native/libcore_icu_ICU.cpp2
-rw-r--r--luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp13
5 files changed, 25 insertions, 16 deletions
diff --git a/luni/src/main/java/java/text/DecimalFormatSymbols.java b/luni/src/main/java/java/text/DecimalFormatSymbols.java
index fba2d6e..85f71a6 100644
--- a/luni/src/main/java/java/text/DecimalFormatSymbols.java
+++ b/luni/src/main/java/java/text/DecimalFormatSymbols.java
@@ -47,7 +47,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
private char decimalSeparator;
private char groupingSeparator;
private char patternSeparator;
- private char percent;
+ private String percent;
private char perMill;
private char monetarySeparator;
private String minusSign;
@@ -306,6 +306,11 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
return minusSign;
}
+ /** @hide */
+ public String getPercentString() {
+ return percent;
+ }
+
/**
* Returns the character which represents the decimal point in a monetary
* value.
@@ -341,7 +346,10 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
* @return the percent character.
*/
public char getPercent() {
- return percent;
+ if (percent.length() == 1) {
+ return percent.charAt(0);
+ }
+ throw new UnsupportedOperationException("Percent spans multiple characters: " + percent);
}
/**
@@ -378,7 +386,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
result = 31*result + decimalSeparator;
result = 31*result + groupingSeparator;
result = 31*result + patternSeparator;
- result = 31*result + percent;
+ result = 31*result + percent.hashCode();
result = 31*result + perMill;
result = 31*result + monetarySeparator;
result = 31*result + minusSign.hashCode();
@@ -544,7 +552,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
* the percent character.
*/
public void setPercent(char value) {
- this.percent = value;
+ this.percent = String.valueOf(value);
}
/**
diff --git a/luni/src/main/java/libcore/icu/LocaleData.java b/luni/src/main/java/libcore/icu/LocaleData.java
index 9e07244..5ce6837 100644
--- a/luni/src/main/java/libcore/icu/LocaleData.java
+++ b/luni/src/main/java/libcore/icu/LocaleData.java
@@ -96,7 +96,7 @@ public final class LocaleData {
public char decimalSeparator;
public char groupingSeparator;
public char patternSeparator;
- public char percent;
+ public String percent;
public char perMill;
public char monetarySeparator;
public String minusSign;
diff --git a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
index fd179c1..cf11ac7 100644
--- a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
+++ b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
@@ -158,7 +158,7 @@ public final class NativeDecimalFormat implements Cloneable {
dfs.getGroupingSeparator(), dfs.getInfinity(),
dfs.getInternationalCurrencySymbol(), dfs.getMinusSignString(),
dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
+ dfs.getPercentString(), dfs.getPerMill(), dfs.getZeroDigit());
this.lastPattern = pattern;
} catch (NullPointerException npe) {
throw npe;
@@ -269,7 +269,7 @@ public final class NativeDecimalFormat implements Cloneable {
dfs.getDigit(), dfs.getExponentSeparator(), dfs.getGroupingSeparator(),
dfs.getInfinity(), dfs.getInternationalCurrencySymbol(), dfs.getMinusSignString(),
dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
+ dfs.getPercentString(), dfs.getPerMill(), dfs.getZeroDigit());
}
public void setDecimalFormatSymbols(final LocaleData localeData) {
@@ -626,13 +626,13 @@ public final class NativeDecimalFormat implements Cloneable {
private static native long open(String pattern, String currencySymbol,
char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
String infinity, String internationalCurrencySymbol, String minusSign,
- char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
+ char monetaryDecimalSeparator, String nan, char patternSeparator, String percent,
char perMill, char zeroDigit);
private static native Number parse(long addr, String string, ParsePosition position, boolean parseBigDecimal);
private static native void setDecimalFormatSymbols(long addr, String currencySymbol,
char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
String infinity, String internationalCurrencySymbol, String minusSign,
- char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
+ char monetaryDecimalSeparator, String nan, char patternSeparator, String percent,
char perMill, char zeroDigit);
private static native void setSymbol(long addr, int symbol, String str);
private static native void setAttribute(long addr, int symbol, int i);
diff --git a/luni/src/main/native/libcore_icu_ICU.cpp b/luni/src/main/native/libcore_icu_ICU.cpp
index 1528a2d..d27b11d 100644
--- a/luni/src/main/native/libcore_icu_ICU.cpp
+++ b/luni/src/main/native/libcore_icu_ICU.cpp
@@ -406,7 +406,7 @@ static void setDecimalFormatSymbolsData(JNIEnv* env, jobject obj, Locale& locale
setCharField(env, obj, "decimalSeparator", dfs.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol));
setCharField(env, obj, "groupingSeparator", dfs.getSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol));
setCharField(env, obj, "patternSeparator", dfs.getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol));
- setCharField(env, obj, "percent", dfs.getSymbol(DecimalFormatSymbols::kPercentSymbol));
+ setStringField(env, obj, "percent", dfs.getSymbol(DecimalFormatSymbols::kPercentSymbol));
setCharField(env, obj, "perMill", dfs.getSymbol(DecimalFormatSymbols::kPerMillSymbol));
setCharField(env, obj, "monetarySeparator", dfs.getSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol));
setStringField(env, obj, "minusSign", dfs.getSymbol(DecimalFormatSymbols:: kMinusSignSymbol));
diff --git a/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp b/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
index c0fd42b..8e440e9 100644
--- a/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
+++ b/luni/src/main/native/libcore_icu_NativeDecimalFormat.cpp
@@ -52,13 +52,14 @@ static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
jchar groupingSeparator0, jstring infinity0,
jstring internationalCurrencySymbol0, jstring minusSign0,
jchar monetaryDecimalSeparator, jstring nan0, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
+ jstring percent0, jchar perMill, jchar zeroDigit) {
ScopedJavaUnicodeString currencySymbol(env, currencySymbol0);
ScopedJavaUnicodeString exponentSeparator(env, exponentSeparator0);
ScopedJavaUnicodeString infinity(env, infinity0);
ScopedJavaUnicodeString internationalCurrencySymbol(env, internationalCurrencySymbol0);
ScopedJavaUnicodeString nan(env, nan0);
ScopedJavaUnicodeString minusSign(env, minusSign0);
+ ScopedJavaUnicodeString percent(env, percent0);
UnicodeString groupingSeparator(groupingSeparator0);
DecimalFormatSymbols* result = new DecimalFormatSymbols;
@@ -74,7 +75,7 @@ static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UnicodeString(monetaryDecimalSeparator));
result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString());
result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UnicodeString(patternSeparator));
- result->setSymbol(DecimalFormatSymbols::kPercentSymbol, UnicodeString(percent));
+ result->setSymbol(DecimalFormatSymbols::kPercentSymbol, percent.unicodeString());
result->setSymbol(DecimalFormatSymbols::kPerMillSymbol, UnicodeString(perMill));
// java.text.DecimalFormatSymbols just uses a zero digit,
// but ICU >= 4.6 has a field for each decimal digit.
@@ -96,7 +97,7 @@ static void NativeDecimalFormat_setDecimalFormatSymbols(JNIEnv* env, jclass, jlo
jchar groupingSeparator, jstring infinity,
jstring internationalCurrencySymbol, jstring minusSign,
jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
+ jstring percent, jchar perMill, jchar zeroDigit) {
DecimalFormatSymbols* symbols = makeDecimalFormatSymbols(env,
currencySymbol, decimalSeparator, digit, exponentSeparator, groupingSeparator,
infinity, internationalCurrencySymbol, minusSign,
@@ -110,7 +111,7 @@ static jlong NativeDecimalFormat_open(JNIEnv* env, jclass, jstring pattern0,
jchar groupingSeparator, jstring infinity,
jstring internationalCurrencySymbol, jstring minusSign,
jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
+ jstring percent, jchar perMill, jchar zeroDigit) {
UErrorCode status = U_ZERO_ERROR;
UParseError parseError;
ScopedJavaUnicodeString pattern(env, pattern0);
@@ -368,10 +369,10 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeDecimalFormat, formatDigitList, "(JLjava/lang/String;Llibcore/icu/NativeDecimalFormat$FieldPositionIterator;)[C"),
NATIVE_METHOD(NativeDecimalFormat, getAttribute, "(JI)I"),
NATIVE_METHOD(NativeDecimalFormat, getTextAttribute, "(JI)Ljava/lang/String;"),
- NATIVE_METHOD(NativeDecimalFormat, open, "(Ljava/lang/String;Ljava/lang/String;CCLjava/lang/String;CLjava/lang/String;Ljava/lang/String;Ljava/lang/String;CLjava/lang/String;CCCC)J"),
+ NATIVE_METHOD(NativeDecimalFormat, open, "(Ljava/lang/String;Ljava/lang/String;CCLjava/lang/String;CLjava/lang/String;Ljava/lang/String;Ljava/lang/String;CLjava/lang/String;CLjava/lang/String;CC)J"),
NATIVE_METHOD(NativeDecimalFormat, parse, "(JLjava/lang/String;Ljava/text/ParsePosition;Z)Ljava/lang/Number;"),
NATIVE_METHOD(NativeDecimalFormat, setAttribute, "(JII)V"),
- NATIVE_METHOD(NativeDecimalFormat, setDecimalFormatSymbols, "(JLjava/lang/String;CCLjava/lang/String;CLjava/lang/String;Ljava/lang/String;Ljava/lang/String;CLjava/lang/String;CCCC)V"),
+ NATIVE_METHOD(NativeDecimalFormat, setDecimalFormatSymbols, "(JLjava/lang/String;CCLjava/lang/String;CLjava/lang/String;Ljava/lang/String;Ljava/lang/String;CLjava/lang/String;CLjava/lang/String;CC)V"),
NATIVE_METHOD(NativeDecimalFormat, setRoundingMode, "(JID)V"),
NATIVE_METHOD(NativeDecimalFormat, setSymbol, "(JILjava/lang/String;)V"),
NATIVE_METHOD(NativeDecimalFormat, setTextAttribute, "(JILjava/lang/String;)V"),