ICU-7438 Add handling of POSIX variant as u-va-posix language tag

X-SVN-Rev: 28031
This commit is contained in:
John Emmons 2010-05-06 21:47:16 +00:00
parent c126788bab
commit 70fa16f19f
3 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and *
* Copyright (C) 2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -32,6 +32,8 @@ public class LanguageTag {
private static final SortedMap<Character, Extension> EMPTY_EXTENSION_MAP = new TreeMap<Character, Extension>();
private static final UnicodeLocaleExtension VA_POSIX = new UnicodeLocaleExtension().put("va", "posix");
//
// Language tag parser instances
//
@ -269,6 +271,7 @@ public class LanguageTag {
}
public String getID() {
boolean putPosixExtension = false;
if (_grandfathered.length() > 0) {
return _grandfathered;
}
@ -291,10 +294,22 @@ public class LanguageTag {
}
if (_variants.size() > 0) {
for (String var : _variants) {
// Special handling of the POSIX variant - treat it as a unicode locale extension
if ( var.equals("posix")) {
if (_extensions.containsKey(UnicodeLocaleExtension.SINGLETON)){
UnicodeLocaleExtension uext = (UnicodeLocaleExtension) _extensions.get(UnicodeLocaleExtension.SINGLETON);
uext.put("va","posix");
_extensions.put(UnicodeLocaleExtension.SINGLETON, uext);
} else {
_extensions.put(UnicodeLocaleExtension.SINGLETON, VA_POSIX);
putPosixExtension = true;
}
} else {
buf.append(SEP);
buf.append(var);
}
}
}
if (_extensions.size() > 0) {
Set<Entry<Character, Extension>> exts = _extensions.entrySet();
for (Entry<Character, Extension> ext : exts) {
@ -304,6 +319,12 @@ public class LanguageTag {
buf.append(ext.getValue().getValue());
}
}
// If we added the POSIX extension explicitly, need to remove it here
// otherwise it will hang around until the next call.
if ( putPosixExtension ) {
_extensions.remove(UnicodeLocaleExtension.SINGLETON);
}
}
if (_privateuse.length() > 0) {
if (buf.length() > 0) {

View File

@ -3106,8 +3106,13 @@ public final class ULocale implements Serializable {
// convert to legacy key/type
String lkey = bcp47ToLDMLKey(bcpKey);
String ltype = bcp47ToLDMLType(lkey, bcpType);
// special handling for u-va-posix, since this is a variant, not a keyword
if (lkey.equals("va") && ltype.equals("posix")) {
id = id + "_POSIX";
} else {
kwds.put(lkey, ltype);
}
}
} else {
kwds.put(String.valueOf(key), ext.getValue());
}

View File

@ -3717,7 +3717,8 @@ public class ULocaleTest extends TestFmwk {
{"en_US", "en-US"},
{"iw_IL", "he-IL"},
{"sr_Latn_SR", "sr-Latn-SR"},
{"en__POSIX", "en-posix"},
{"en_US_POSIX@ca=japanese", "en-US-u-ca-japanese-va-posix"},
{"en__POSIX", "en-u-va-posix"},
// {"en_POSIX", "en"}, /* ICU4J locale parser successfully parse en_POSIX as language:en/variant:POSIX */
{"und_555", "und-555"},
{"123", "und"},
@ -3744,6 +3745,8 @@ public class ULocaleTest extends TestFmwk {
{"en@timezone=US/Eastern", "en-u-tz-usnyc"},
{"en@x=x-y-z;a=a-b-c", "en-x-x-y-z"},
{"it@collation=badcollationtype;colStrength=identical;cu=usd-eur", "it-u-ks-identic"},
{"en_US_POSIX", "en-US-u-va-posix"},
{"en_US_POSIX@calendar=japanese;currency=EUR","en-US-u-ca-japanese-cu-eur-va-posix"},
};
for (int i = 0; i < locale_to_langtag.length; i++) {
@ -3785,6 +3788,7 @@ public class ULocaleTest extends TestFmwk {
{"und-varzero-var1-vartwo", "__VARZERO", Integer.valueOf(12)},
{"en-u-ca-gregory", "en@calendar=gregorian", NOERROR},
{"en-U-cu-USD", "en@currency=usd", NOERROR},
{"en-us-u-va-posix", "en_US_POSIX", NOERROR},
{"ar-x-1-2-3", "ar@x=1-2-3", NOERROR},
{"fr-u-nu-latn-cu-eur", "fr@currency=eur;numbers=latn", NOERROR},
{"de-k-kext-u-co-phonebk-nu-latn", "de@collation=phonebook;k=kext;numbers=latn", NOERROR},