/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*******************************************************************************
* Copyright (C) 2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
public class LanguageTag {
//
// static fields
//
//
// Language subtag fields
//
// Map contains grandfathered tags and its preferred mappings from
// Keys are lower-case strings.
static {
// grandfathered = irregular ; non-redundant tags registered
// / regular ; during the RFC 3066 era
//
// irregular = "en-GB-oed" ; irregular tags do not match
// / "i-ami" ; the 'langtag' production and
// / "i-bnn" ; would not otherwise be
// / "i-default" ; considered 'well-formed'
// / "i-enochian" ; These tags are all valid,
// / "i-hak" ; but most are deprecated
// / "i-klingon" ; in favor of more modern
// / "i-lux" ; subtags or subtag
// / "i-mingo" ; combination
// / "i-navajo"
// / "i-pwn"
// / "i-tao"
// / "i-tay"
// / "i-tsu"
// / "sgn-BE-FR"
// / "sgn-BE-NL"
// / "sgn-CH-DE"
//
// regular = "art-lojban" ; these tags match the 'langtag'
// / "cel-gaulish" ; production, but their subtags
// / "no-bok" ; are not extended language
// / "no-nyn" ; or variant subtags: their meaning
// / "zh-guoyu" ; is defined by their registration
// / "zh-hakka" ; and all of these are deprecated
// / "zh-min" ; in favor of a more modern
// / "zh-min-nan" ; subtag or sequence of subtags
// / "zh-xiang"
//{"tag", "preferred"},
{"art-lojban", "jbo"},
{"cel-gaulish", "xtg-x-cel-gaulish"}, // fallback
{"en-GB-oed", "en-GB-x-oed"}, // fallback
{"i-ami", "ami"},
{"i-bnn", "bnn"},
{"i-default", "en-x-i-default"}, // fallback
{"i-enochian", "und-x-i-enochian"}, // fallback
{"i-hak", "hak"},
{"i-klingon", "tlh"},
{"i-lux", "lb"},
{"i-mingo", "see-x-i-mingo"}, // fallback
{"i-navajo", "nv"},
{"i-pwn", "pwn"},
{"i-tao", "tao"},
{"i-tay", "tay"},
{"i-tsu", "tsu"},
{"no-bok", "nb"},
{"no-nyn", "nn"},
{"sgn-BE-FR", "sfb"},
{"sgn-BE-NL", "vgt"},
{"sgn-CH-DE", "sgg"},
{"zh-guoyu", "cmn"},
{"zh-hakka", "hak"},
{"zh-min", "nan-x-zh-min"}, // fallback
{"zh-min-nan", "nan"},
{"zh-xiang", "hsn"},
};
}
}
private LanguageTag() {
}
/*
* BNF in RFC5464
*
* Language-Tag = langtag ; normal language tags
* / privateuse ; private use tag
* / grandfathered ; grandfathered tags
*
*
* langtag = language
* ["-" script]
* ["-" region]
* *("-" variant)
* *("-" extension)
* ["-" privateuse]
*
* language = 2*3ALPHA ; shortest ISO 639 code
* ["-" extlang] ; sometimes followed by
* ; extended language subtags
* / 4ALPHA ; or reserved for future use
* / 5*8ALPHA ; or registered language subtag
*
* extlang = 3ALPHA ; selected ISO 639 codes
* *2("-" 3ALPHA) ; permanently reserved
*
* script = 4ALPHA ; ISO 15924 code
*
* region = 2ALPHA ; ISO 3166-1 code
* / 3DIGIT ; UN M.49 code
*
* variant = 5*8alphanum ; registered variants
* / (DIGIT 3alphanum)
*
* extension = singleton 1*("-" (2*8alphanum))
*
* ; Single alphanumerics
* ; "x" reserved for private use
* singleton = DIGIT ; 0 - 9
* / %x41-57 ; A - W
* / %x59-5A ; Y - Z
* / %x61-77 ; a - w
* / %x79-7A ; y - z
*
* privateuse = "x" 1*("-" (1*8alphanum))
*
*/
sts = new ParseStatus();
} else {
}
// Check if the tag is grandfathered
// use preferred mapping
} else {
}
// langtag must start with either language or privateuse
}
if (s.length() == 0) {
} else {
}
}
return tag;
}
//
// Language subtag parsers
//
return false;
}
boolean found = false;
if (isLanguage(s)) {
found = true;
language = s;
}
return found;
}
return false;
}
boolean found = false;
if (!isExtlang(s)) {
break;
}
found = true;
}
// Maximum 3 extlangs
break;
}
}
return found;
}
return false;
}
boolean found = false;
if (isScript(s)) {
found = true;
script = s;
}
return found;
}
return false;
}
boolean found = false;
if (isRegion(s)) {
found = true;
region = s;
}
return found;
}
return false;
}
boolean found = false;
if (!isVariant(s)) {
break;
}
found = true;
}
}
return found;
}
return false;
}
boolean found = false;
if (isExtensionSingleton(s)) {
if (isExtensionSubtag(s)) {
} else {
break;
}
}
break;
}
if (extensions.isEmpty()) {
}
found = true;
} else {
break;
}
}
return found;
}
return false;
}
boolean found = false;
if (isPrivateusePrefix(s)) {
if (!isPrivateuseSubtag(s)) {
break;
}
}
// need at least 1 private subtag
} else {
found = true;
}
}
return found;
}
boolean hasSubtag = false;
if (isLanguage(language)) {
// Convert a deprecated language code to its new code
language = "he";
language = "yi";
language = "id";
}
}
hasSubtag = true;
}
hasSubtag = true;
}
// Special handling for no_NO_NY - use nn_NO for language tag
variant = "";
}
break;
}
}
}
hasSubtag = true;
}
// ill-formed variant subtags
if (!isPrivateuseSubtag(prvv)) {
// cannot use private use subtag - truncated
break;
}
}
}
}
}
}
if (localeExtensions != null) {
if (isPrivateusePrefixChar(locextKey)) {
} else {
if (extensions == null) {
extensions = new ArrayList<>();
}
}
}
}
if (extensions != null) {
hasSubtag = true;
}
// append ill-formed variant subtags to private use
if (privuseVar != null) {
if (privateuse == null) {
} else {
}
}
if (privateuse != null) {
}
// use lang "und" when 1) no language is available AND
// 2) any of other subtags other than private use are available or
// no private use tag is available
}
return tag;
}
//
// Getter methods for language subtag fields
//
return language;
}
return Collections.emptyList();
}
}
return script;
}
return region;
}
return Collections.emptyList();
}
}
if (extensions.isEmpty()) {
return Collections.emptyList();
}
}
return privateuse;
}
//
// Language subtag syntax checking methods
//
// language = 2*3ALPHA ; shortest ISO 639 code
// ["-" extlang] ; sometimes followed by
// ; extended language subtags
// / 4ALPHA ; or reserved for future use
// / 5*8ALPHA ; or registered language subtag
}
// extlang = 3ALPHA ; selected ISO 639 codes
// *2("-" 3ALPHA) ; permanently reserved
}
// script = 4ALPHA ; ISO 15924 code
}
// region = 2ALPHA ; ISO 3166-1 code
// / 3DIGIT ; UN M.49 code
}
// variant = 5*8alphanum ; registered variants
// / (DIGIT 3alphanum)
return LocaleUtils.isAlphaNumericString(s);
}
if (len == 4) {
}
return false;
}
// singleton = DIGIT ; 0 - 9
// / %x41-57 ; A - W
// / %x59-5A ; Y - Z
// / %x61-77 ; a - w
// / %x79-7A ; y - z
return (s.length() == 1)
&& LocaleUtils.isAlphaString(s)
}
public static boolean isExtensionSingletonChar(char c) {
}
// extension = singleton 1*("-" (2*8alphanum))
}
// privateuse = "x" 1*("-" (1*8alphanum))
return (s.length() == 1)
}
public static boolean isPrivateusePrefixChar(char c) {
}
// privateuse = "x" 1*("-" (1*8alphanum))
}
//
// Language subtag canonicalization methods
//
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toTitleString(s);
}
return LocaleUtils.toUpperString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
return LocaleUtils.toLowerString(s);
}
}
}
}
}
}
}
}
}
}
}