+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
* Copyright (C) 2014-2016, International Business Machines
UBool SimpleFormatter::applyPatternMinMaxArguments(
const UnicodeString &pattern,
- int32_t min, int32_t max,
+ int32_t min, int32_t max, UBool removeSingleQuotes,
UErrorCode &errorCode) {
if (U_FAILURE(errorCode)) {
return FALSE;
// skip the quote-ending apostrophe
inQuote = FALSE;
continue;
- } else if (c == OPEN_BRACE || c == CLOSE_BRACE) {
+ } else if (removeSingleQuotes || c == OPEN_BRACE || c == CLOSE_BRACE) {
// Skip the quote-starting apostrophe, find the end of the quoted literal text.
++i;
inQuote = TRUE;
}
UnicodeString SimpleFormatter::getTextWithNoArguments(
- const UChar *compiledPattern, int32_t compiledPatternLength) {
+ const UChar *compiledPattern,
+ int32_t compiledPatternLength,
+ int32_t* offsets,
+ int32_t offsetsLength) {
+ for (int32_t i = 0; i < offsetsLength; i++) {
+ offsets[i] = -1;
+ }
int32_t capacity = compiledPatternLength - 1 -
getArgumentLimit(compiledPattern, compiledPatternLength);
UnicodeString sb(capacity, 0, 0); // Java: StringBuilder
for (int32_t i = 1; i < compiledPatternLength;) {
- int32_t segmentLength = compiledPattern[i++] - ARG_NUM_LIMIT;
- if (segmentLength > 0) {
- sb.append(compiledPattern + i, segmentLength);
- i += segmentLength;
+ int32_t n = compiledPattern[i++];
+ if (n > ARG_NUM_LIMIT) {
+ n -= ARG_NUM_LIMIT;
+ sb.append(compiledPattern + i, n);
+ i += n;
+ } else if (n < offsetsLength) {
+ offsets[n] = sb.length();
}
}
return sb;