]> granicus.if.org Git - icu/commitdiff
ICU-10221 Fixed parsed length issue with a grandfathered tag in LanguageTag parser...
authorYoshito Umaoka <y.umaoka@gmail.com>
Thu, 13 Jun 2013 14:41:39 +0000 (14:41 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Thu, 13 Jun 2013 14:41:39 +0000 (14:41 +0000)
X-SVN-Rev: 33822

icu4j/main/classes/core/src/com/ibm/icu/impl/locale/LanguageTag.java

index 8a4d87ff14e57195e41b4d45d429079dd2dad173..f159e0b1efa8ee918dff6be4a2bb9e80f7296dd1 100644 (file)
@@ -163,12 +163,14 @@ public class LanguageTag {
         }
 
         StringTokenIterator itr;
+        boolean isGrandfathered = false;
 
         // Check if the tag is grandfathered
         String[] gfmap = GRANDFATHERED.get(new AsciiUtil.CaseInsensitiveKey(languageTag));
         if (gfmap != null) {
             // use preferred mapping
             itr = new StringTokenIterator(gfmap[1], SEP);
+            isGrandfathered = true;
         } else {
             itr = new StringTokenIterator(languageTag, SEP);
         }
@@ -185,7 +187,13 @@ public class LanguageTag {
         }
         tag.parsePrivateuse(itr, sts);
 
-        if (!itr.isDone() && !sts.isError()) {
+        if (isGrandfathered) {
+            // Grandfathered tag is replaced with a well-formed tag above.
+            // However, the parsed length must be the original tag length.
+            assert (itr.isDone());
+            assert (!sts.isError());
+            sts._parseLength = languageTag.length();
+        } else if (!itr.isDone() && !sts.isError()) {
             String s = itr.current();
             sts._errorIndex = itr.currentStart();
             if (s.length() == 0) {