From bcfcd53be91ef60823914dcd88a210acf25f69f0 Mon Sep 17 00:00:00 2001 From: Peter Edberg Date: Thu, 5 Sep 2013 22:13:07 +0000 Subject: [PATCH] ICU-10161 trimMarksFromAffix must trim all marks; update "ar" number patterns to latest X-SVN-Rev: 34203 --- icu4c/source/data/locales/ar.txt | 6 ++--- icu4c/source/i18n/decimfmt.cpp | 31 ++++++++++++++----------- icu4c/source/test/intltest/numfmtst.cpp | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/icu4c/source/data/locales/ar.txt b/icu4c/source/data/locales/ar.txt index 4b88cbd349c..2860e547bd5 100644 --- a/icu4c/source/data/locales/ar.txt +++ b/icu4c/source/data/locales/ar.txt @@ -23,8 +23,8 @@ ar{ NumberElements{ arab{ patterns{ - currencyFormat{"¤ #0.00;¤ #0.00-"} - decimalFormat{"#0.###"} + currencyFormat{"¤ #,##0.00"} + decimalFormat{"#,##0.###"} percentFormat{"#,##0%"} scientificFormat{"#E0"} } @@ -44,7 +44,7 @@ ar{ default{"arab"} latn{ patterns{ - currencyFormat{"¤ #,##0.00;¤ #,##0.00-"} + currencyFormat{"¤ #,##0.00"} decimalFormat{"#,##0.###"} percentFormat{"#,##0%"} scientificFormat{"#E0"} diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index 13e3073f9ed..72b2e76cb72 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -2904,23 +2904,24 @@ static UBool equalWithSignCompatibility(UChar32 lhs, UChar32 rhs) { // check for LRM 0x200E, RLM 0x200F, ALM 0x061C #define IS_BIDI_MARK(c) (c==0x200E || c==0x200F || c==0x061C) -// The following assumes any marks are at the beginning or end of the affix +#define TRIM_BUFLEN 32 UnicodeString& DecimalFormat::trimMarksFromAffix(const UnicodeString& affix, UnicodeString& trimmedAffix) { - int32_t first = 0; - int32_t last = affix.length() - 1; - if (last > 0) { - UChar c = affix.charAt(0); - if (IS_BIDI_MARK(c)) { - first++; - } - if (last > first) { - c = affix.charAt(last); - if (IS_BIDI_MARK(c)) { - last--; - } + UChar trimBuf[TRIM_BUFLEN]; + int32_t affixLen = affix.length(); + int32_t affixPos, trimLen = 0; + + for (affixPos = 0; affixPos < affixLen; affixPos++) { + UChar c = affix.charAt(affixPos); + if (!IS_BIDI_MARK(c)) { + if (trimLen < TRIM_BUFLEN) { + trimBuf[trimLen++] = c; + } else { + trimLen = 0; + break; + } } } - return trimmedAffix.setTo(affix, first, last + 1 - first); + return (trimLen > 0)? trimmedAffix.setTo(trimBuf, trimLen): trimmedAffix.setTo(affix); } /** @@ -2939,6 +2940,8 @@ int32_t DecimalFormat::compareSimpleAffix(const UnicodeString& affix, UBool lenient) { int32_t start = pos; UnicodeString trimmedAffix; + // For more efficiency we should keep lazily-created trimmed affixes around in + // instance variables instead of trimming each time they are used (the next step) trimMarksFromAffix(affix, trimmedAffix); UChar32 affixChar = trimmedAffix.char32At(0); int32_t affixLength = trimmedAffix.length(); diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 9dbced328fe..4eb1aa7ceb4 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -3092,7 +3092,7 @@ void NumberFormatTest::TestNumberingSystems() { { "en_US@numbers=thai", 1234.567, FALSE, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" }, { "en_US@numbers=hebr", 5678.0, TRUE, "\\u05D4\\u05F3\\u05EA\\u05E8\\u05E2\\u05F4\\u05D7" }, { "en_US@numbers=arabext", 1234.567, FALSE, "\\u06F1\\u066c\\u06F2\\u06F3\\u06F4\\u066b\\u06F5\\u06F6\\u06F7" }, - { "ar_EG", 1234.567, FALSE, "\\u0661\\u0662\\u0663\\u0664\\u066b\\u0665\\u0666\\u0667" }, + { "ar_EG", 1234.567, FALSE, "\\u0661\\u066C\\u0662\\u0663\\u0664\\u066b\\u0665\\u0666\\u0667" }, { "th_TH@numbers=traditional", 1234.567, FALSE, "\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57" }, // fall back to native per TR35 { "ar_MA", 1234.567, FALSE, "1.234,567" }, { "en_US@numbers=hanidec", 1234.567, FALSE, "\\u4e00,\\u4e8c\\u4e09\\u56db.\\u4e94\\u516d\\u4e03" }, -- 2.40.0