summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-02-17 13:46:16 +0000
committerNarayan Kamath <narayan@google.com>2015-02-18 14:25:18 +0000
commitde75c0aa34c7db47ddec1704e94fa05c54687705 (patch)
treea63f3e6b6c1ac4a558351370c6037e645a56c094 /luni
parent6ebd116201512baf0cee39584fbf4ad19f7972b7 (diff)
downloadlibcore-de75c0aa34c7db47ddec1704e94fa05c54687705.zip
libcore-de75c0aa34c7db47ddec1704e94fa05c54687705.tar.gz
libcore-de75c0aa34c7db47ddec1704e94fa05c54687705.tar.bz2
Fix handling of consecutive quotes in ChoiceFormat et al.
Two consecutive single quotes ('') must be interpreted as an escaped single quite sequence. We were implementing it by simply keeping track of whether the last character was a single quote. This is insufficient for sequences of three or more quotes since we shouldn't emit ('') for an escape sequence of ('''). We'll have to keep track of the number of consecutive quotes we've seen in the input instead. This is a partial fix for the bug below. There appears to be another bug in MessageFormat itself in its handling of subpatterns. bug: 19011159 Change-Id: Ia71e5d8c1962356cabc265cf80ebc0a04ff84f17
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/text/Format.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/luni/src/main/java/java/text/Format.java b/luni/src/main/java/java/text/Format.java
index 58671fa..c4dc5f0 100644
--- a/luni/src/main/java/java/text/Format.java
+++ b/luni/src/main/java/java/text/Format.java
@@ -177,23 +177,26 @@ public abstract class Format implements Serializable, Cloneable {
static boolean upTo(String string, ParsePosition position,
StringBuffer buffer, char stop) {
int index = position.getIndex(), length = string.length();
- boolean lastQuote = false, quote = false;
+
+ int numConsecutiveQuotes = 0;
+ boolean quote = false;
while (index < length) {
char ch = string.charAt(index++);
if (ch == '\'') {
- if (lastQuote) {
+ ++numConsecutiveQuotes;
+ if (numConsecutiveQuotes != 0 && numConsecutiveQuotes % 2 == 0) {
buffer.append('\'');
}
quote = !quote;
- lastQuote = true;
} else if (ch == stop && !quote) {
position.setIndex(index);
return true;
} else {
- lastQuote = false;
+ numConsecutiveQuotes = 0;
buffer.append(ch);
}
}
+
position.setIndex(index);
return false;
}