From 408820999cc27695e854a03eed18aa4c90a845d7 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Thu, 13 Jun 2013 14:41:39 +0000 Subject: [PATCH] ICU-10221 Fixed parsed length issue with a grandfathered tag in LanguageTag parser implementation. X-SVN-Rev: 33822 --- .../core/src/com/ibm/icu/impl/locale/LanguageTag.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/LanguageTag.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/LanguageTag.java index 8a4d87ff14e..f159e0b1efa 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/LanguageTag.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/LanguageTag.java @@ -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) { -- 2.40.0