]> granicus.if.org Git - icu/commitdiff
ICU-13374 Fixed localized GMT offset format roundtrip in Perisian locale.
authorYoshito Umaoka <y.umaoka@gmail.com>
Thu, 28 Sep 2017 00:53:39 +0000 (00:53 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Thu, 28 Sep 2017 00:53:39 +0000 (00:53 +0000)
X-SVN-Rev: 40493

icu4c/source/i18n/tzfmt.cpp
icu4c/source/test/intltest/tzfmttst.cpp
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java

index 50277c24ef4ef8f1f04628ffec958c007a89ba7d..a65907867974b9e90fd5d786ec54ae24810caa27 100644 (file)
@@ -18,6 +18,7 @@
 #include "unicode/uchar.h"
 #include "unicode/udat.h"
 #include "unicode/ustring.h"
+#include "unicode/utf16.h"
 #include "tzgnames.h"
 #include "cmemory.h"
 #include "cstring.h"
@@ -30,6 +31,7 @@
 #include "uvector.h"
 #include "zonemeta.h"
 #include "tznames_impl.h"   // TextTrieMap
+#include "patternprops.h"
 
 U_NAMESPACE_BEGIN
 
@@ -1862,6 +1864,27 @@ TimeZoneFormat::parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t
         if (fieldType == GMTOffsetField::TEXT) {
             const UChar* patStr = field->getPatternText();
             len = u_strlen(patStr);
+            if (i == 0) {
+                // When TimeZoneFormat parse() is called from SimpleDateFormat,
+                // leading space characters might be truncated. If the first pattern text
+                // starts with such character (e.g. Bidi control), then we need to
+                // skip the leading space charcters.
+                if (!PatternProps::isWhiteSpace(text.char32At(idx))) {
+                    for (;;) {
+                        UChar32 ch;
+                        int32_t chLen;
+                        U16_GET(patStr, 0, 0, len, ch)
+                        if (PatternProps::isWhiteSpace(ch)) {
+                            chLen = U16_LENGTH(ch);
+                            len -= chLen;
+                            patStr += chLen;
+                        }
+                        else {
+                            break;
+                        }
+                    }
+                }
+            }
             if (text.caseCompare(idx, len, patStr, 0) != 0) {
                 failed = TRUE;
                 break;
index d2a841f54334a36631da6f0d220f32f237473732..2cb1eabd06d7eee25a5cc921168091e796ca65fa 100644 (file)
@@ -140,7 +140,8 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) {
         Locale("en"),
         Locale("en_CA"),
         Locale("fr"),
-        Locale("zh_Hant")
+        Locale("zh_Hant"),
+        Locale("fa")
     };
 
     const Locale *LOCALES;
@@ -162,9 +163,6 @@ TimeZoneFormatTest::TestTimeZoneRoundTrip(void) {
         if (uprv_strcmp(LOCALES[locidx].getLanguage(),"ccp")==0 && logKnownIssue("13366", "Skip handling ccp until TimeZone offset roundtrip is fixed")) {
             continue;
         }
-        if (uprv_strcmp(LOCALES[locidx].getLanguage(),"fa")==0 && logKnownIssue("13374", "Skip handling fa until TimeZone offset roundtrip is fixed")) {
-            continue;
-        }
         UnicodeString localGMTString;
         SimpleDateFormat gmtFmt(UnicodeString("ZZZZ"), LOCALES[locidx], status);
         if (U_FAILURE(status)) {
index ea907cee4ce6f10c99dcdd9ddd24be51784c6d47..e3719cfd9712677d76949e9e4ec24140b70eefaf 100644 (file)
@@ -128,7 +128,7 @@ public class TimeZoneFormatTest extends TestFmwk {
         if (TEST_ALL || TestFmwk.getExhaustiveness() > 5) {
             LOCALES = ULocale.getAvailableLocales();
         } else {
-            LOCALES = new ULocale[] {new ULocale("en"), new ULocale("en_CA"), new ULocale("fr"), new ULocale("zh_Hant")};
+            LOCALES = new ULocale[] {new ULocale("en"), new ULocale("en_CA"), new ULocale("fr"), new ULocale("zh_Hant"), new ULocale("fa")};
         }
 
         String[] tzids;