intl/icu/source/common/locmap.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/locmap.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1137 @@
     1.4 +/*
     1.5 + **********************************************************************
     1.6 + *   Copyright (C) 1996-2013, International Business Machines
     1.7 + *   Corporation and others.  All Rights Reserved.
     1.8 + **********************************************************************
     1.9 + *
    1.10 + * Provides functionality for mapping between
    1.11 + * LCID and Posix IDs or ICU locale to codepage
    1.12 + *
    1.13 + * Note: All classes and code in this file are
    1.14 + *       intended for internal use only.
    1.15 + *
    1.16 + * Methods of interest:
    1.17 + *   unsigned long convertToLCID(const char*);
    1.18 + *   const char* convertToPosix(unsigned long);
    1.19 + *
    1.20 + * Kathleen Wilson, 4/30/96
    1.21 + *
    1.22 + *  Date        Name        Description
    1.23 + *  3/11/97     aliu        Fixed off-by-one bug in assignment operator. Added
    1.24 + *                          setId() method and safety check against 
    1.25 + *                          MAX_ID_LENGTH.
    1.26 + * 04/23/99     stephen     Added C wrapper for convertToPosix.
    1.27 + * 09/18/00     george      Removed the memory leaks.
    1.28 + * 08/23/01     george      Convert to C
    1.29 + */
    1.30 +
    1.31 +#include "locmap.h"
    1.32 +#include "cstring.h"
    1.33 +#include "cmemory.h"
    1.34 +
    1.35 +#if U_PLATFORM == U_PF_WINDOWS && defined(_MSC_VER) && (_MSC_VER >= 1500)
    1.36 +/*
    1.37 + * TODO: It seems like we should widen this to
    1.38 + * either U_PLATFORM_USES_ONLY_WIN32_API (includes MinGW)
    1.39 + * or U_PLATFORM_HAS_WIN32_API (includes MinGW and Cygwin)
    1.40 + * but those use gcc and won't have defined(_MSC_VER).
    1.41 + * We might need to #include some Windows header and test for some version macro from there.
    1.42 + * Or call some Windows function and see what it returns.
    1.43 + */
    1.44 +#define USE_WINDOWS_LOCALE_API
    1.45 +#endif
    1.46 +
    1.47 +#ifdef USE_WINDOWS_LOCALE_API
    1.48 +#include <windows.h>
    1.49 +#include <winnls.h>
    1.50 +#endif
    1.51 +
    1.52 +/*
    1.53 + * Note:
    1.54 + * The mapping from Win32 locale ID numbers to POSIX locale strings should
    1.55 + * be the faster one.
    1.56 + *
    1.57 + * Many LCID values come from winnt.h
    1.58 + * Some also come from http://www.microsoft.com/globaldev/reference/lcid-all.mspx
    1.59 + */
    1.60 +
    1.61 +/*
    1.62 +////////////////////////////////////////////////
    1.63 +//
    1.64 +// Internal Classes for LCID <--> POSIX Mapping
    1.65 +//
    1.66 +/////////////////////////////////////////////////
    1.67 +*/
    1.68 +
    1.69 +typedef struct ILcidPosixElement
    1.70 +{
    1.71 +    const uint32_t hostID;
    1.72 +    const char * const posixID;
    1.73 +} ILcidPosixElement;
    1.74 +
    1.75 +typedef struct ILcidPosixMap
    1.76 +{
    1.77 +    const uint32_t numRegions;
    1.78 +    const struct ILcidPosixElement* const regionMaps;
    1.79 +} ILcidPosixMap;
    1.80 +
    1.81 +
    1.82 +/*
    1.83 +/////////////////////////////////////////////////
    1.84 +//
    1.85 +// Easy macros to make the LCID <--> POSIX Mapping
    1.86 +//
    1.87 +/////////////////////////////////////////////////
    1.88 +*/
    1.89 +
    1.90 +/**
    1.91 + * The standard one language/one country mapping for LCID.
    1.92 + * The first element must be the language, and the following
    1.93 + * elements are the language with the country.
    1.94 + * @param hostID LCID in host format such as 0x044d
    1.95 + * @param languageID posix ID of just the language such as 'de'
    1.96 + * @param posixID posix ID of the language_TERRITORY such as 'de_CH'
    1.97 + */
    1.98 +#define ILCID_POSIX_ELEMENT_ARRAY(hostID, languageID, posixID) \
    1.99 +static const ILcidPosixElement locmap_ ## languageID [] = { \
   1.100 +    {LANGUAGE_LCID(hostID), #languageID},     /* parent locale */ \
   1.101 +    {hostID, #posixID}, \
   1.102 +};
   1.103 +
   1.104 +/**
   1.105 + * Define a subtable by ID
   1.106 + * @param id the POSIX ID, either a language or language_TERRITORY
   1.107 + */
   1.108 +#define ILCID_POSIX_SUBTABLE(id) \
   1.109 +static const ILcidPosixElement locmap_ ## id [] =
   1.110 +
   1.111 +
   1.112 +/**
   1.113 + * Create the map for the posixID. This macro supposes that the language string
   1.114 + * name is the same as the global variable name, and that the first element
   1.115 + * in the ILcidPosixElement is just the language.
   1.116 + * @param _posixID the full POSIX ID for this entry.
   1.117 + */
   1.118 +#define ILCID_POSIX_MAP(_posixID) \
   1.119 +    {sizeof(locmap_ ## _posixID)/sizeof(ILcidPosixElement), locmap_ ## _posixID}
   1.120 +
   1.121 +/*
   1.122 +////////////////////////////////////////////
   1.123 +//
   1.124 +// Create the table of LCID to POSIX Mapping
   1.125 +// None of it should be dynamically created.
   1.126 +//
   1.127 +// Keep static locale variables inside the function so that
   1.128 +// it can be created properly during static init.
   1.129 +//
   1.130 +// Note: This table should be updated periodically. Check the National Lanaguage Support API Reference Website.
   1.131 +//       Microsoft is moving away from LCID in favor of locale name as of Vista.  This table needs to be
   1.132 +//       maintained for support of older Windows version.
   1.133 +//       Update: Windows 7 (091130)
   1.134 +//
   1.135 +// Note: Microsoft assign a different LCID if a locale has a sorting variant. POSIX IDs below may contain
   1.136 +//       @collation=XXX, but no other keywords are allowed (at least for now). When uprv_convertToLCID() is
   1.137 +//       called from uloc_getLCID(), keywords other than collation are already removed. If we really need
   1.138 +//       to support other keywords in this mapping data, we must update the implementation.
   1.139 +////////////////////////////////////////////
   1.140 +*/
   1.141 +
   1.142 +ILCID_POSIX_ELEMENT_ARRAY(0x0436, af, af_ZA)
   1.143 +
   1.144 +ILCID_POSIX_SUBTABLE(ar) {
   1.145 +    {0x01,   "ar"},
   1.146 +    {0x3801, "ar_AE"},
   1.147 +    {0x3c01, "ar_BH"},
   1.148 +    {0x1401, "ar_DZ"},
   1.149 +    {0x0c01, "ar_EG"},
   1.150 +    {0x0801, "ar_IQ"},
   1.151 +    {0x2c01, "ar_JO"},
   1.152 +    {0x3401, "ar_KW"},
   1.153 +    {0x3001, "ar_LB"},
   1.154 +    {0x1001, "ar_LY"},
   1.155 +    {0x1801, "ar_MA"},
   1.156 +    {0x1801, "ar_MO"},
   1.157 +    {0x2001, "ar_OM"},
   1.158 +    {0x4001, "ar_QA"},
   1.159 +    {0x0401, "ar_SA"},
   1.160 +    {0x2801, "ar_SY"},
   1.161 +    {0x1c01, "ar_TN"},
   1.162 +    {0x2401, "ar_YE"}
   1.163 +};
   1.164 +
   1.165 +ILCID_POSIX_ELEMENT_ARRAY(0x044d, as, as_IN)
   1.166 +ILCID_POSIX_ELEMENT_ARRAY(0x045e, am, am_ET)
   1.167 +ILCID_POSIX_ELEMENT_ARRAY(0x047a, arn,arn_CL)
   1.168 +
   1.169 +ILCID_POSIX_SUBTABLE(az) {
   1.170 +    {0x2c,   "az"},
   1.171 +    {0x082c, "az_Cyrl_AZ"},  /* Cyrillic based */
   1.172 +    {0x742c, "az_Cyrl"},  /* Cyrillic based */
   1.173 +    {0x042c, "az_Latn_AZ"}, /* Latin based */
   1.174 +    {0x782c, "az_Latn"}, /* Latin based */
   1.175 +    {0x042c, "az_AZ"} /* Latin based */
   1.176 +};
   1.177 +
   1.178 +ILCID_POSIX_ELEMENT_ARRAY(0x046d, ba, ba_RU)
   1.179 +ILCID_POSIX_ELEMENT_ARRAY(0x0423, be, be_BY)
   1.180 +
   1.181 +/*ILCID_POSIX_SUBTABLE(ber) {
   1.182 +    {0x5f,   "ber"},
   1.183 +    {0x045f, "ber_Arab_DZ"},
   1.184 +    {0x045f, "ber_Arab"},
   1.185 +    {0x085f, "ber_Latn_DZ"},
   1.186 +    {0x085f, "ber_Latn"}
   1.187 +};*/
   1.188 +
   1.189 +ILCID_POSIX_ELEMENT_ARRAY(0x0402, bg, bg_BG)
   1.190 +
   1.191 +ILCID_POSIX_ELEMENT_ARRAY(0x0466, bin, bin_NG)
   1.192 +
   1.193 +ILCID_POSIX_SUBTABLE(bn) {
   1.194 +    {0x45,   "bn"},
   1.195 +    {0x0845, "bn_BD"},
   1.196 +    {0x0445, "bn_IN"}
   1.197 +};
   1.198 +
   1.199 +ILCID_POSIX_SUBTABLE(bo) {
   1.200 +    {0x51,   "bo"},
   1.201 +    {0x0851, "bo_BT"},
   1.202 +    {0x0451, "bo_CN"}
   1.203 +};
   1.204 +
   1.205 +ILCID_POSIX_ELEMENT_ARRAY(0x047e, br, br_FR)
   1.206 +
   1.207 +ILCID_POSIX_SUBTABLE(ca) {
   1.208 +    {0x03,   "ca"},
   1.209 +    {0x0403, "ca_ES"},
   1.210 +    {0x0803, "ca_ES_VALENCIA"}
   1.211 +};
   1.212 +
   1.213 +ILCID_POSIX_ELEMENT_ARRAY(0x0483, co, co_FR)
   1.214 +ILCID_POSIX_ELEMENT_ARRAY(0x045c, chr,chr_US)
   1.215 +
   1.216 +ILCID_POSIX_SUBTABLE(ckb) {
   1.217 +    {0x92,   "ckb"},
   1.218 +    {0x92,   "ku"},
   1.219 +    {0x7c92, "ckb_Arab"},
   1.220 +    {0x7c92, "ku_Arab"},
   1.221 +    {0x0492, "ckb_Arab_IQ"},
   1.222 +    {0x0492, "ku_Arab_IQ"}
   1.223 +};
   1.224 +
   1.225 +/* Declared as cs_CZ to get around compiler errors on z/OS, which defines cs as a function */
   1.226 +ILCID_POSIX_ELEMENT_ARRAY(0x0405, cs, cs_CZ)
   1.227 +
   1.228 +ILCID_POSIX_ELEMENT_ARRAY(0x0452, cy, cy_GB)
   1.229 +ILCID_POSIX_ELEMENT_ARRAY(0x0406, da, da_DK)
   1.230 +
   1.231 +ILCID_POSIX_SUBTABLE(de) {
   1.232 +    {0x07,   "de"},
   1.233 +    {0x0c07, "de_AT"},
   1.234 +    {0x0807, "de_CH"},
   1.235 +    {0x0407, "de_DE"},
   1.236 +    {0x1407, "de_LI"},
   1.237 +    {0x1007, "de_LU"},
   1.238 +    {0x10407,"de_DE@collation=phonebook"},  /*This is really de_DE_PHONEBOOK on Windows*/
   1.239 +    {0x10407,"de@collation=phonebook"}  /*This is really de_DE_PHONEBOOK on Windows*/
   1.240 +};
   1.241 +
   1.242 +ILCID_POSIX_ELEMENT_ARRAY(0x0465, dv, dv_MV)
   1.243 +ILCID_POSIX_ELEMENT_ARRAY(0x0408, el, el_GR)
   1.244 +
   1.245 +ILCID_POSIX_SUBTABLE(en) {
   1.246 +    {0x09,   "en"},
   1.247 +    {0x0c09, "en_AU"},
   1.248 +    {0x2809, "en_BZ"},
   1.249 +    {0x1009, "en_CA"},
   1.250 +    {0x0809, "en_GB"},
   1.251 +    {0x3c09, "en_HK"},
   1.252 +    {0x3809, "en_ID"},
   1.253 +    {0x1809, "en_IE"},
   1.254 +    {0x4009, "en_IN"},
   1.255 +    {0x2009, "en_JM"},
   1.256 +    {0x4409, "en_MY"},
   1.257 +    {0x1409, "en_NZ"},
   1.258 +    {0x3409, "en_PH"},
   1.259 +    {0x4809, "en_SG"},
   1.260 +    {0x2C09, "en_TT"},
   1.261 +    {0x0409, "en_US"},
   1.262 +    {0x007f, "en_US_POSIX"}, /* duplicate for roundtripping */
   1.263 +    {0x2409, "en_VI"},  /* Virgin Islands AKA Caribbean Islands (en_CB). */
   1.264 +    {0x1c09, "en_ZA"},
   1.265 +    {0x3009, "en_ZW"},
   1.266 +    {0x2409, "en_029"},
   1.267 +    {0x0409, "en_AS"},  /* Alias for en_US. Leave last. */
   1.268 +    {0x0409, "en_GU"},  /* Alias for en_US. Leave last. */
   1.269 +    {0x0409, "en_MH"},  /* Alias for en_US. Leave last. */
   1.270 +    {0x0409, "en_MP"},  /* Alias for en_US. Leave last. */
   1.271 +    {0x0409, "en_UM"}   /* Alias for en_US. Leave last. */
   1.272 +};
   1.273 +
   1.274 +ILCID_POSIX_SUBTABLE(en_US_POSIX) {
   1.275 +    {0x007f, "en_US_POSIX"} /* duplicate for roundtripping */
   1.276 +};
   1.277 +
   1.278 +ILCID_POSIX_SUBTABLE(es) {
   1.279 +    {0x0a,   "es"},
   1.280 +    {0x2c0a, "es_AR"},
   1.281 +    {0x400a, "es_BO"},
   1.282 +    {0x340a, "es_CL"},
   1.283 +    {0x240a, "es_CO"},
   1.284 +    {0x140a, "es_CR"},
   1.285 +    {0x1c0a, "es_DO"},
   1.286 +    {0x300a, "es_EC"},
   1.287 +    {0x0c0a, "es_ES"},      /*Modern sort.*/
   1.288 +    {0x100a, "es_GT"},
   1.289 +    {0x480a, "es_HN"},
   1.290 +    {0x080a, "es_MX"},
   1.291 +    {0x4c0a, "es_NI"},
   1.292 +    {0x180a, "es_PA"},
   1.293 +    {0x280a, "es_PE"},
   1.294 +    {0x500a, "es_PR"},
   1.295 +    {0x3c0a, "es_PY"},
   1.296 +    {0x440a, "es_SV"},
   1.297 +    {0x540a, "es_US"},
   1.298 +    {0x380a, "es_UY"},
   1.299 +    {0x200a, "es_VE"},
   1.300 +    {0xe40a, "es_419"},
   1.301 +    {0x040a, "es_ES@collation=traditional"},
   1.302 +    {0x040a, "es@collation=traditional"}
   1.303 +};
   1.304 +
   1.305 +ILCID_POSIX_ELEMENT_ARRAY(0x0425, et, et_EE)
   1.306 +ILCID_POSIX_ELEMENT_ARRAY(0x042d, eu, eu_ES)
   1.307 +
   1.308 +/* ISO-639 doesn't distinguish between Persian and Dari.*/
   1.309 +ILCID_POSIX_SUBTABLE(fa) {
   1.310 +    {0x29,   "fa"},
   1.311 +    {0x0429, "fa_IR"},  /* Persian/Farsi (Iran) */
   1.312 +    {0x048c, "fa_AF"}   /* Persian/Dari (Afghanistan) */
   1.313 +};
   1.314 +
   1.315 +/* duplicate for roundtripping */
   1.316 +ILCID_POSIX_SUBTABLE(fa_AF) {
   1.317 +    {0x8c,   "fa_AF"},  /* Persian/Dari (Afghanistan) */
   1.318 +    {0x048c, "fa_AF"}   /* Persian/Dari (Afghanistan) */
   1.319 +};
   1.320 +
   1.321 +ILCID_POSIX_SUBTABLE(ff) {
   1.322 +    {0x67,   "ff"},
   1.323 +    {0x7c67, "ff_Latn"},
   1.324 +    {0x0867, "ff_Latn_SN"}
   1.325 +};
   1.326 +
   1.327 +ILCID_POSIX_ELEMENT_ARRAY(0x040b, fi, fi_FI)
   1.328 +ILCID_POSIX_ELEMENT_ARRAY(0x0464, fil,fil_PH)
   1.329 +ILCID_POSIX_ELEMENT_ARRAY(0x0438, fo, fo_FO)
   1.330 +
   1.331 +ILCID_POSIX_SUBTABLE(fr) {
   1.332 +    {0x0c,   "fr"},
   1.333 +    {0x080c, "fr_BE"},
   1.334 +    {0x0c0c, "fr_CA"},
   1.335 +    {0x240c, "fr_CD"},
   1.336 +    {0x240c, "fr_CG"},
   1.337 +    {0x100c, "fr_CH"},
   1.338 +    {0x300c, "fr_CI"},
   1.339 +    {0x2c0c, "fr_CM"},
   1.340 +    {0x040c, "fr_FR"},
   1.341 +    {0x3c0c, "fr_HT"},
   1.342 +    {0x140c, "fr_LU"},
   1.343 +    {0x380c, "fr_MA"},
   1.344 +    {0x180c, "fr_MC"},
   1.345 +    {0x340c, "fr_ML"},
   1.346 +    {0x200c, "fr_RE"},
   1.347 +    {0x280c, "fr_SN"},
   1.348 +    {0xe40c, "fr_015"},
   1.349 +    {0x1c0c, "fr_029"}
   1.350 +};
   1.351 +
   1.352 +ILCID_POSIX_ELEMENT_ARRAY(0x0467, fuv, fuv_NG)
   1.353 +
   1.354 +ILCID_POSIX_ELEMENT_ARRAY(0x0462, fy, fy_NL)
   1.355 +
   1.356 +ILCID_POSIX_SUBTABLE(ga) { /* Gaelic (Ireland) */
   1.357 +    {0x3c,   "ga"},
   1.358 +    {0x083c, "ga_IE"},
   1.359 +    {0x043c, "gd_GB"}
   1.360 +};
   1.361 +
   1.362 +ILCID_POSIX_SUBTABLE(gd) { /* Gaelic (Scotland) */
   1.363 +    {0x91,   "gd"},
   1.364 +    {0x0491, "gd_GB"}
   1.365 +};
   1.366 +
   1.367 +ILCID_POSIX_ELEMENT_ARRAY(0x0456, gl, gl_ES)
   1.368 +ILCID_POSIX_ELEMENT_ARRAY(0x0447, gu, gu_IN)
   1.369 +ILCID_POSIX_ELEMENT_ARRAY(0x0474, gn, gn_PY)
   1.370 +ILCID_POSIX_ELEMENT_ARRAY(0x0484, gsw,gsw_FR)
   1.371 +
   1.372 +ILCID_POSIX_SUBTABLE(ha) {
   1.373 +    {0x68,   "ha"},
   1.374 +    {0x7c68, "ha_Latn"},
   1.375 +    {0x0468, "ha_Latn_NG"},
   1.376 +};
   1.377 +
   1.378 +ILCID_POSIX_ELEMENT_ARRAY(0x0475, haw,haw_US)
   1.379 +ILCID_POSIX_ELEMENT_ARRAY(0x040d, he, he_IL)
   1.380 +ILCID_POSIX_ELEMENT_ARRAY(0x0439, hi, hi_IN)
   1.381 +
   1.382 +/* This LCID is really four different locales.*/
   1.383 +ILCID_POSIX_SUBTABLE(hr) {
   1.384 +    {0x1a,   "hr"},
   1.385 +    {0x141a, "bs_Latn_BA"},  /* Bosnian, Bosnia and Herzegovina */
   1.386 +    {0x681a, "bs_Latn"},  /* Bosnian, Bosnia and Herzegovina */
   1.387 +    {0x141a, "bs_BA"},  /* Bosnian, Bosnia and Herzegovina */
   1.388 +    {0x781a, "bs"},     /* Bosnian */
   1.389 +    {0x201a, "bs_Cyrl_BA"},  /* Bosnian, Bosnia and Herzegovina */
   1.390 +    {0x641a, "bs_Cyrl"},  /* Bosnian, Bosnia and Herzegovina */
   1.391 +    {0x101a, "hr_BA"},  /* Croatian in Bosnia */
   1.392 +    {0x041a, "hr_HR"},  /* Croatian*/
   1.393 +    {0x2c1a, "sr_Latn_ME"},
   1.394 +    {0x241a, "sr_Latn_RS"},
   1.395 +    {0x181a, "sr_Latn_BA"}, /* Serbo-Croatian in Bosnia */
   1.396 +    {0x081a, "sr_Latn_CS"}, /* Serbo-Croatian*/
   1.397 +    {0x701a, "sr_Latn"},    /* It's 0x1a or 0x081a, pick one to make the test program happy. */
   1.398 +    {0x1c1a, "sr_Cyrl_BA"}, /* Serbo-Croatian in Bosnia */
   1.399 +    {0x0c1a, "sr_Cyrl_CS"}, /* Serbian*/
   1.400 +    {0x301a, "sr_Cyrl_ME"},
   1.401 +    {0x281a, "sr_Cyrl_RS"},
   1.402 +    {0x6c1a, "sr_Cyrl"},    /* It's 0x1a or 0x0c1a, pick one to make the test program happy. */
   1.403 +    {0x7c1a, "sr"}          /* In CLDR sr is sr_Cyrl. */
   1.404 +};
   1.405 +
   1.406 +ILCID_POSIX_ELEMENT_ARRAY(0x040e, hu, hu_HU)
   1.407 +ILCID_POSIX_ELEMENT_ARRAY(0x042b, hy, hy_AM)
   1.408 +ILCID_POSIX_ELEMENT_ARRAY(0x0469, ibb, ibb_NG)
   1.409 +ILCID_POSIX_ELEMENT_ARRAY(0x0421, id, id_ID)
   1.410 +ILCID_POSIX_ELEMENT_ARRAY(0x0470, ig, ig_NG)
   1.411 +ILCID_POSIX_ELEMENT_ARRAY(0x0478, ii, ii_CN)
   1.412 +ILCID_POSIX_ELEMENT_ARRAY(0x040f, is, is_IS)
   1.413 +
   1.414 +ILCID_POSIX_SUBTABLE(it) {
   1.415 +    {0x10,   "it"},
   1.416 +    {0x0810, "it_CH"},
   1.417 +    {0x0410, "it_IT"}
   1.418 +};
   1.419 +
   1.420 +ILCID_POSIX_SUBTABLE(iu) {
   1.421 +    {0x5d,   "iu"},
   1.422 +    {0x045d, "iu_Cans_CA"},
   1.423 +    {0x785d, "iu_Cans"},
   1.424 +    {0x085d, "iu_Latn_CA"},
   1.425 +    {0x7c5d, "iu_Latn"}
   1.426 +};
   1.427 +
   1.428 +ILCID_POSIX_ELEMENT_ARRAY(0x040d, iw, iw_IL)    /*Left in for compatibility*/
   1.429 +ILCID_POSIX_ELEMENT_ARRAY(0x0411, ja, ja_JP)
   1.430 +ILCID_POSIX_ELEMENT_ARRAY(0x0437, ka, ka_GE)
   1.431 +ILCID_POSIX_ELEMENT_ARRAY(0x043f, kk, kk_KZ)
   1.432 +ILCID_POSIX_ELEMENT_ARRAY(0x046f, kl, kl_GL)
   1.433 +ILCID_POSIX_ELEMENT_ARRAY(0x0453, km, km_KH)
   1.434 +ILCID_POSIX_ELEMENT_ARRAY(0x044b, kn, kn_IN)
   1.435 +
   1.436 +ILCID_POSIX_SUBTABLE(ko) {
   1.437 +    {0x12,   "ko"},
   1.438 +    {0x0812, "ko_KP"},
   1.439 +    {0x0412, "ko_KR"}
   1.440 +};
   1.441 +
   1.442 +ILCID_POSIX_ELEMENT_ARRAY(0x0457, kok, kok_IN)
   1.443 +ILCID_POSIX_ELEMENT_ARRAY(0x0471, kr,  kr_NG)
   1.444 +
   1.445 +ILCID_POSIX_SUBTABLE(ks) {         /* We could add PK and CN too */
   1.446 +    {0x60,   "ks"},
   1.447 +    {0x0860, "ks_IN"},              /* Documentation doesn't mention script */
   1.448 +    {0x0460, "ks_Arab_IN"},
   1.449 +    {0x0860, "ks_Deva_IN"}
   1.450 +};
   1.451 +
   1.452 +ILCID_POSIX_ELEMENT_ARRAY(0x0440, ky, ky_KG)   /* Kyrgyz is spoken in Kyrgyzstan */
   1.453 +ILCID_POSIX_ELEMENT_ARRAY(0x0476, la, la_IT)   /* TODO: Verify the country */
   1.454 +ILCID_POSIX_ELEMENT_ARRAY(0x046e, lb, lb_LU)
   1.455 +ILCID_POSIX_ELEMENT_ARRAY(0x0454, lo, lo_LA)
   1.456 +ILCID_POSIX_ELEMENT_ARRAY(0x0427, lt, lt_LT)
   1.457 +ILCID_POSIX_ELEMENT_ARRAY(0x0426, lv, lv_LV)
   1.458 +ILCID_POSIX_ELEMENT_ARRAY(0x0481, mi, mi_NZ)
   1.459 +ILCID_POSIX_ELEMENT_ARRAY(0x042f, mk, mk_MK)
   1.460 +ILCID_POSIX_ELEMENT_ARRAY(0x044c, ml, ml_IN)
   1.461 +
   1.462 +ILCID_POSIX_SUBTABLE(mn) {
   1.463 +    {0x50,   "mn"},
   1.464 +    {0x0450, "mn_MN"},
   1.465 +    {0x7c50, "mn_Mong"},
   1.466 +    {0x0850, "mn_Mong_CN"},
   1.467 +    {0x0850, "mn_CN"},
   1.468 +    {0x7850, "mn_Cyrl"}
   1.469 +};
   1.470 +
   1.471 +ILCID_POSIX_ELEMENT_ARRAY(0x0458, mni,mni_IN)
   1.472 +ILCID_POSIX_ELEMENT_ARRAY(0x047c, moh,moh_CA)
   1.473 +ILCID_POSIX_ELEMENT_ARRAY(0x044e, mr, mr_IN)
   1.474 +
   1.475 +ILCID_POSIX_SUBTABLE(ms) {
   1.476 +    {0x3e,   "ms"},
   1.477 +    {0x083e, "ms_BN"},   /* Brunei Darussalam*/
   1.478 +    {0x043e, "ms_MY"}    /* Malaysia*/
   1.479 +};
   1.480 +
   1.481 +ILCID_POSIX_ELEMENT_ARRAY(0x043a, mt, mt_MT)
   1.482 +ILCID_POSIX_ELEMENT_ARRAY(0x0455, my, my_MM)
   1.483 +
   1.484 +ILCID_POSIX_SUBTABLE(ne) {
   1.485 +    {0x61,   "ne"},
   1.486 +    {0x0861, "ne_IN"},   /* India*/
   1.487 +    {0x0461, "ne_NP"}    /* Nepal*/
   1.488 +};
   1.489 +
   1.490 +ILCID_POSIX_SUBTABLE(nl) {
   1.491 +    {0x13,   "nl"},
   1.492 +    {0x0813, "nl_BE"},
   1.493 +    {0x0413, "nl_NL"}
   1.494 +};
   1.495 +
   1.496 +/* The "no" locale split into nb and nn.  By default in ICU, "no" is nb.*/
   1.497 +ILCID_POSIX_SUBTABLE(no) {
   1.498 +    {0x14,   "no"},     /* really nb_NO */
   1.499 +    {0x7c14, "nb"},     /* really nb */
   1.500 +    {0x0414, "nb_NO"},  /* really nb_NO. Keep first in the 414 list. */
   1.501 +    {0x0414, "no_NO"},  /* really nb_NO */
   1.502 +    {0x0814, "nn_NO"},  /* really nn_NO. Keep first in the 814 list.  */
   1.503 +    {0x7814, "nn"},     /* It's 0x14 or 0x814, pick one to make the test program happy. */
   1.504 +    {0x0814, "no_NO_NY"}/* really nn_NO */
   1.505 +};
   1.506 +
   1.507 +ILCID_POSIX_ELEMENT_ARRAY(0x046c, nso,nso_ZA)   /* TODO: Verify the ISO-639 code */
   1.508 +ILCID_POSIX_ELEMENT_ARRAY(0x0482, oc, oc_FR)
   1.509 +
   1.510 +ILCID_POSIX_SUBTABLE(om) { /* TODO: Verify the country */
   1.511 +    {0x72,   "om"},
   1.512 +    {0x0472, "om_ET"},
   1.513 +    {0x0472, "gaz_ET"}
   1.514 +};
   1.515 +
   1.516 +/* Declared as or_IN to get around compiler errors*/
   1.517 +ILCID_POSIX_SUBTABLE(or_IN) {
   1.518 +    {0x48,   "or"},
   1.519 +    {0x0448, "or_IN"},
   1.520 +};
   1.521 +
   1.522 +
   1.523 +ILCID_POSIX_SUBTABLE(pa) {
   1.524 +    {0x46,   "pa"},
   1.525 +    {0x0446, "pa_IN"},
   1.526 +    {0x0846, "pa_PK"},
   1.527 +    {0x0846, "pa_Arab_PK"}
   1.528 +};
   1.529 +
   1.530 +ILCID_POSIX_ELEMENT_ARRAY(0x0479, pap, pap_AN)
   1.531 +ILCID_POSIX_ELEMENT_ARRAY(0x0415, pl, pl_PL)
   1.532 +ILCID_POSIX_ELEMENT_ARRAY(0x0463, ps, ps_AF)
   1.533 +
   1.534 +ILCID_POSIX_SUBTABLE(pt) {
   1.535 +    {0x16,   "pt"},
   1.536 +    {0x0416, "pt_BR"},
   1.537 +    {0x0816, "pt_PT"}
   1.538 +};
   1.539 +
   1.540 +ILCID_POSIX_SUBTABLE(qu) {
   1.541 +    {0x6b,   "qu"},
   1.542 +    {0x046b, "qu_BO"},
   1.543 +    {0x086b, "qu_EC"},
   1.544 +    {0x0C6b, "qu_PE"},
   1.545 +    {0x046b, "quz_BO"},
   1.546 +    {0x086b, "quz_EC"},
   1.547 +    {0x0C6b, "quz_PE"}
   1.548 +};
   1.549 +
   1.550 +ILCID_POSIX_ELEMENT_ARRAY(0x0486, qut, qut_GT) /* qut is an ISO-639-3 code */
   1.551 +ILCID_POSIX_ELEMENT_ARRAY(0x0417, rm, rm_CH)
   1.552 +
   1.553 +ILCID_POSIX_SUBTABLE(ro) {
   1.554 +    {0x18,   "ro"},
   1.555 +    {0x0418, "ro_RO"},
   1.556 +    {0x0818, "ro_MD"}
   1.557 +};
   1.558 +
   1.559 +ILCID_POSIX_SUBTABLE(root) {
   1.560 +    {0x00,   "root"}
   1.561 +};
   1.562 +
   1.563 +ILCID_POSIX_SUBTABLE(ru) {
   1.564 +    {0x19,   "ru"},
   1.565 +    {0x0419, "ru_RU"},
   1.566 +    {0x0819, "ru_MD"}
   1.567 +};
   1.568 +
   1.569 +ILCID_POSIX_ELEMENT_ARRAY(0x0487, rw, rw_RW)
   1.570 +ILCID_POSIX_ELEMENT_ARRAY(0x044f, sa, sa_IN)
   1.571 +ILCID_POSIX_ELEMENT_ARRAY(0x0485, sah,sah_RU)
   1.572 +
   1.573 +ILCID_POSIX_SUBTABLE(sd) {
   1.574 +    {0x59,   "sd"},
   1.575 +    {0x0459, "sd_IN"},
   1.576 +    {0x0859, "sd_PK"}
   1.577 +};
   1.578 +
   1.579 +ILCID_POSIX_SUBTABLE(se) {
   1.580 +    {0x3b,   "se"},
   1.581 +    {0x0c3b, "se_FI"},
   1.582 +    {0x043b, "se_NO"},
   1.583 +    {0x083b, "se_SE"},
   1.584 +    {0x783b, "sma"},
   1.585 +    {0x183b, "sma_NO"},
   1.586 +    {0x1c3b, "sma_SE"},
   1.587 +    {0x7c3b, "smj"},
   1.588 +    {0x703b, "smn"},
   1.589 +    {0x743b, "sms"},
   1.590 +    {0x103b, "smj_NO"},
   1.591 +    {0x143b, "smj_SE"},
   1.592 +    {0x243b, "smn_FI"},
   1.593 +    {0x203b, "sms_FI"},
   1.594 +};
   1.595 +
   1.596 +ILCID_POSIX_ELEMENT_ARRAY(0x045b, si, si_LK)
   1.597 +ILCID_POSIX_ELEMENT_ARRAY(0x041b, sk, sk_SK)
   1.598 +ILCID_POSIX_ELEMENT_ARRAY(0x0424, sl, sl_SI)
   1.599 +
   1.600 +ILCID_POSIX_SUBTABLE(so) { /* TODO: Verify the country */
   1.601 +    {0x77,   "so"},
   1.602 +    {0x0477, "so_ET"},
   1.603 +    {0x0477, "so_SO"}
   1.604 +};
   1.605 +
   1.606 +ILCID_POSIX_ELEMENT_ARRAY(0x041c, sq, sq_AL)
   1.607 +ILCID_POSIX_ELEMENT_ARRAY(0x0430, st, st_ZA)
   1.608 +
   1.609 +ILCID_POSIX_SUBTABLE(sv) {
   1.610 +    {0x1d,   "sv"},
   1.611 +    {0x081d, "sv_FI"},
   1.612 +    {0x041d, "sv_SE"}
   1.613 +};
   1.614 +
   1.615 +ILCID_POSIX_ELEMENT_ARRAY(0x0441, sw, sw_KE)
   1.616 +ILCID_POSIX_ELEMENT_ARRAY(0x045A, syr, syr_SY)
   1.617 +
   1.618 +ILCID_POSIX_SUBTABLE(ta) {
   1.619 +    {0x49,   "ta"},
   1.620 +    {0x0449, "ta_IN"},
   1.621 +    {0x0849, "ta_LK"}
   1.622 +};
   1.623 +
   1.624 +ILCID_POSIX_ELEMENT_ARRAY(0x044a, te, te_IN)
   1.625 +
   1.626 +/* Cyrillic based by default */
   1.627 +ILCID_POSIX_SUBTABLE(tg) {
   1.628 +    {0x28,   "tg"},
   1.629 +    {0x7c28, "tg_Cyrl"},
   1.630 +    {0x0428, "tg_Cyrl_TJ"}
   1.631 +};
   1.632 +
   1.633 +ILCID_POSIX_ELEMENT_ARRAY(0x041e, th, th_TH)
   1.634 +
   1.635 +ILCID_POSIX_SUBTABLE(ti) {
   1.636 +    {0x73,   "ti"},
   1.637 +    {0x0873, "ti_ER"},
   1.638 +    {0x0473, "ti_ET"}
   1.639 +};
   1.640 +
   1.641 +ILCID_POSIX_ELEMENT_ARRAY(0x0442, tk, tk_TM)
   1.642 +
   1.643 +ILCID_POSIX_SUBTABLE(tn) {
   1.644 +    {0x32,   "tn"},
   1.645 +    {0x0832, "tn_BW"},
   1.646 +    {0x0432, "tn_ZA"}
   1.647 +};
   1.648 +
   1.649 +ILCID_POSIX_ELEMENT_ARRAY(0x041f, tr, tr_TR)
   1.650 +ILCID_POSIX_ELEMENT_ARRAY(0x0431, ts, ts_ZA)
   1.651 +ILCID_POSIX_ELEMENT_ARRAY(0x0444, tt, tt_RU)
   1.652 +
   1.653 +ILCID_POSIX_SUBTABLE(tzm) {
   1.654 +    {0x5f,   "tzm"},
   1.655 +    {0x7c5f, "tzm_Latn"},
   1.656 +    {0x085f, "tzm_Latn_DZ"},
   1.657 +    {0x105f, "tzm_Tfng_MA"},
   1.658 +    {0x045f, "tmz"}
   1.659 +};
   1.660 +
   1.661 +ILCID_POSIX_SUBTABLE(ug) {
   1.662 +    {0x80,   "ug"},
   1.663 +    {0x0480, "ug_CN"},
   1.664 +    {0x0480, "ug_Arab_CN"}
   1.665 +};
   1.666 +
   1.667 +ILCID_POSIX_ELEMENT_ARRAY(0x0422, uk, uk_UA)
   1.668 +
   1.669 +ILCID_POSIX_SUBTABLE(ur) {
   1.670 +    {0x20,   "ur"},
   1.671 +    {0x0820, "ur_IN"},
   1.672 +    {0x0420, "ur_PK"}
   1.673 +};
   1.674 +
   1.675 +ILCID_POSIX_SUBTABLE(uz) {
   1.676 +    {0x43,   "uz"},
   1.677 +    {0x0843, "uz_Cyrl_UZ"},  /* Cyrillic based */
   1.678 +    {0x7843, "uz_Cyrl"},  /* Cyrillic based */
   1.679 +    {0x0843, "uz_UZ"},  /* Cyrillic based */
   1.680 +    {0x0443, "uz_Latn_UZ"}, /* Latin based */
   1.681 +    {0x7c43, "uz_Latn"} /* Latin based */
   1.682 +};
   1.683 +
   1.684 +ILCID_POSIX_SUBTABLE(ve) { /* TODO: Verify the country */
   1.685 +    {0x33,   "ve"},
   1.686 +    {0x0433, "ve_ZA"},
   1.687 +    {0x0433, "ven_ZA"}
   1.688 +};
   1.689 +
   1.690 +ILCID_POSIX_ELEMENT_ARRAY(0x042a, vi, vi_VN)
   1.691 +
   1.692 +ILCID_POSIX_SUBTABLE(wen) {
   1.693 +    {0x2E,   "wen"},
   1.694 +    {0x042E, "wen_DE"},
   1.695 +    {0x042E, "hsb_DE"},
   1.696 +    {0x082E, "dsb_DE"},
   1.697 +    {0x7C2E, "dsb"},
   1.698 +    {0x2E,   "hsb"}
   1.699 +};
   1.700 +
   1.701 +ILCID_POSIX_ELEMENT_ARRAY(0x0488, wo, wo_SN)
   1.702 +ILCID_POSIX_ELEMENT_ARRAY(0x0434, xh, xh_ZA)
   1.703 +ILCID_POSIX_ELEMENT_ARRAY(0x043d, yi, yi)
   1.704 +ILCID_POSIX_ELEMENT_ARRAY(0x046a, yo, yo_NG)
   1.705 +
   1.706 +ILCID_POSIX_SUBTABLE(zh) {
   1.707 +    {0x0004, "zh_Hans"},
   1.708 +    {0x7804, "zh"},
   1.709 +    {0x0804, "zh_CN"},
   1.710 +    {0x0804, "zh_Hans_CN"},
   1.711 +    {0x0c04, "zh_Hant_HK"},
   1.712 +    {0x0c04, "zh_HK"},
   1.713 +    {0x1404, "zh_Hant_MO"},
   1.714 +    {0x1404, "zh_MO"},
   1.715 +    {0x1004, "zh_Hans_SG"},
   1.716 +    {0x1004, "zh_SG"},
   1.717 +    {0x0404, "zh_Hant_TW"},
   1.718 +    {0x7c04, "zh_Hant"},
   1.719 +    {0x0404, "zh_TW"},
   1.720 +    {0x30404,"zh_Hant_TW"},     /* Bopomofo order */
   1.721 +    {0x30404,"zh_TW"},          /* Bopomofo order */
   1.722 +    {0x20004,"zh@collation=stroke"},
   1.723 +    {0x20404,"zh_Hant@collation=stroke"},
   1.724 +    {0x20404,"zh_Hant_TW@collation=stroke"},
   1.725 +    {0x20404,"zh_TW@collation=stroke"},
   1.726 +    {0x20804,"zh_Hans@collation=stroke"},
   1.727 +    {0x20804,"zh_Hans_CN@collation=stroke"},
   1.728 +    {0x20804,"zh_CN@collation=stroke"}
   1.729 +};
   1.730 +
   1.731 +ILCID_POSIX_ELEMENT_ARRAY(0x0435, zu, zu_ZA)
   1.732 +
   1.733 +/* This must be static and grouped by LCID. */
   1.734 +static const ILcidPosixMap gPosixIDmap[] = {
   1.735 +    ILCID_POSIX_MAP(af),    /*  af  Afrikaans                 0x36 */
   1.736 +    ILCID_POSIX_MAP(am),    /*  am  Amharic                   0x5e */
   1.737 +    ILCID_POSIX_MAP(ar),    /*  ar  Arabic                    0x01 */
   1.738 +    ILCID_POSIX_MAP(arn),   /*  arn Araucanian/Mapudungun     0x7a */
   1.739 +    ILCID_POSIX_MAP(as),    /*  as  Assamese                  0x4d */
   1.740 +    ILCID_POSIX_MAP(az),    /*  az  Azerbaijani               0x2c */
   1.741 +    ILCID_POSIX_MAP(ba),    /*  ba  Bashkir                   0x6d */
   1.742 +    ILCID_POSIX_MAP(be),    /*  be  Belarusian                0x23 */
   1.743 +/*    ILCID_POSIX_MAP(ber),     ber Berber/Tamazight          0x5f */
   1.744 +    ILCID_POSIX_MAP(bg),    /*  bg  Bulgarian                 0x02 */
   1.745 +    ILCID_POSIX_MAP(bin),   /*  bin Edo                       0x66 */
   1.746 +    ILCID_POSIX_MAP(bn),    /*  bn  Bengali; Bangla           0x45 */
   1.747 +    ILCID_POSIX_MAP(bo),    /*  bo  Tibetan                   0x51 */
   1.748 +    ILCID_POSIX_MAP(br),    /*  br  Breton                    0x7e */
   1.749 +    ILCID_POSIX_MAP(ca),    /*  ca  Catalan                   0x03 */
   1.750 +    ILCID_POSIX_MAP(chr),   /*  chr Cherokee                  0x5c */
   1.751 +    ILCID_POSIX_MAP(ckb),   /*  ckb Sorani (Central Kurdish)  0x92 */
   1.752 +    ILCID_POSIX_MAP(co),    /*  co  Corsican                  0x83 */
   1.753 +    ILCID_POSIX_MAP(cs),    /*  cs  Czech                     0x05 */
   1.754 +    ILCID_POSIX_MAP(cy),    /*  cy  Welsh                     0x52 */
   1.755 +    ILCID_POSIX_MAP(da),    /*  da  Danish                    0x06 */
   1.756 +    ILCID_POSIX_MAP(de),    /*  de  German                    0x07 */
   1.757 +    ILCID_POSIX_MAP(dv),    /*  dv  Divehi                    0x65 */
   1.758 +    ILCID_POSIX_MAP(el),    /*  el  Greek                     0x08 */
   1.759 +    ILCID_POSIX_MAP(en),    /*  en  English                   0x09 */
   1.760 +    ILCID_POSIX_MAP(en_US_POSIX), /*    invariant             0x7f */
   1.761 +    ILCID_POSIX_MAP(es),    /*  es  Spanish                   0x0a */
   1.762 +    ILCID_POSIX_MAP(et),    /*  et  Estonian                  0x25 */
   1.763 +    ILCID_POSIX_MAP(eu),    /*  eu  Basque                    0x2d */
   1.764 +    ILCID_POSIX_MAP(fa),    /*  fa  Persian/Farsi             0x29 */
   1.765 +    ILCID_POSIX_MAP(fa_AF), /*  fa  Persian/Dari              0x8c */
   1.766 +    ILCID_POSIX_MAP(ff),    /*  ff  Fula                      0x67 */
   1.767 +    ILCID_POSIX_MAP(fi),    /*  fi  Finnish                   0x0b */
   1.768 +    ILCID_POSIX_MAP(fil),   /*  fil Filipino                  0x64 */
   1.769 +    ILCID_POSIX_MAP(fo),    /*  fo  Faroese                   0x38 */
   1.770 +    ILCID_POSIX_MAP(fr),    /*  fr  French                    0x0c */
   1.771 +    ILCID_POSIX_MAP(fuv),   /*  fuv Fulfulde - Nigeria        0x67 */
   1.772 +    ILCID_POSIX_MAP(fy),    /*  fy  Frisian                   0x62 */
   1.773 +    ILCID_POSIX_MAP(ga),    /*  *   Gaelic (Ireland,Scotland) 0x3c */
   1.774 +    ILCID_POSIX_MAP(gd),    /*  gd  Gaelic (United Kingdom)   0x91 */
   1.775 +    ILCID_POSIX_MAP(gl),    /*  gl  Galician                  0x56 */
   1.776 +    ILCID_POSIX_MAP(gn),    /*  gn  Guarani                   0x74 */
   1.777 +    ILCID_POSIX_MAP(gsw),   /*  gsw Alemanic/Alsatian/Swiss German 0x84 */
   1.778 +    ILCID_POSIX_MAP(gu),    /*  gu  Gujarati                  0x47 */
   1.779 +    ILCID_POSIX_MAP(ha),    /*  ha  Hausa                     0x68 */
   1.780 +    ILCID_POSIX_MAP(haw),   /*  haw Hawaiian                  0x75 */
   1.781 +    ILCID_POSIX_MAP(he),    /*  he  Hebrew (formerly iw)      0x0d */
   1.782 +    ILCID_POSIX_MAP(hi),    /*  hi  Hindi                     0x39 */
   1.783 +    ILCID_POSIX_MAP(hr),    /*  *   Croatian and others       0x1a */
   1.784 +    ILCID_POSIX_MAP(hu),    /*  hu  Hungarian                 0x0e */
   1.785 +    ILCID_POSIX_MAP(hy),    /*  hy  Armenian                  0x2b */
   1.786 +    ILCID_POSIX_MAP(ibb),   /*  ibb Ibibio - Nigeria          0x69 */
   1.787 +    ILCID_POSIX_MAP(id),    /*  id  Indonesian (formerly in)  0x21 */
   1.788 +    ILCID_POSIX_MAP(ig),    /*  ig  Igbo                      0x70 */
   1.789 +    ILCID_POSIX_MAP(ii),    /*  ii  Sichuan Yi                0x78 */
   1.790 +    ILCID_POSIX_MAP(is),    /*  is  Icelandic                 0x0f */
   1.791 +    ILCID_POSIX_MAP(it),    /*  it  Italian                   0x10 */
   1.792 +    ILCID_POSIX_MAP(iu),    /*  iu  Inuktitut                 0x5d */
   1.793 +    ILCID_POSIX_MAP(iw),    /*  iw  Hebrew                    0x0d */
   1.794 +    ILCID_POSIX_MAP(ja),    /*  ja  Japanese                  0x11 */
   1.795 +    ILCID_POSIX_MAP(ka),    /*  ka  Georgian                  0x37 */
   1.796 +    ILCID_POSIX_MAP(kk),    /*  kk  Kazakh                    0x3f */
   1.797 +    ILCID_POSIX_MAP(kl),    /*  kl  Kalaallisut               0x6f */
   1.798 +    ILCID_POSIX_MAP(km),    /*  km  Khmer                     0x53 */
   1.799 +    ILCID_POSIX_MAP(kn),    /*  kn  Kannada                   0x4b */
   1.800 +    ILCID_POSIX_MAP(ko),    /*  ko  Korean                    0x12 */
   1.801 +    ILCID_POSIX_MAP(kok),   /*  kok Konkani                   0x57 */
   1.802 +    ILCID_POSIX_MAP(kr),    /*  kr  Kanuri                    0x71 */
   1.803 +    ILCID_POSIX_MAP(ks),    /*  ks  Kashmiri                  0x60 */
   1.804 +    ILCID_POSIX_MAP(ky),    /*  ky  Kyrgyz                    0x40 */
   1.805 +    ILCID_POSIX_MAP(lb),    /*  lb  Luxembourgish             0x6e */
   1.806 +    ILCID_POSIX_MAP(la),    /*  la  Latin                     0x76 */
   1.807 +    ILCID_POSIX_MAP(lo),    /*  lo  Lao                       0x54 */
   1.808 +    ILCID_POSIX_MAP(lt),    /*  lt  Lithuanian                0x27 */
   1.809 +    ILCID_POSIX_MAP(lv),    /*  lv  Latvian, Lettish          0x26 */
   1.810 +    ILCID_POSIX_MAP(mi),    /*  mi  Maori                     0x81 */
   1.811 +    ILCID_POSIX_MAP(mk),    /*  mk  Macedonian                0x2f */
   1.812 +    ILCID_POSIX_MAP(ml),    /*  ml  Malayalam                 0x4c */
   1.813 +    ILCID_POSIX_MAP(mn),    /*  mn  Mongolian                 0x50 */
   1.814 +    ILCID_POSIX_MAP(mni),   /*  mni Manipuri                  0x58 */
   1.815 +    ILCID_POSIX_MAP(moh),   /*  moh Mohawk                    0x7c */
   1.816 +    ILCID_POSIX_MAP(mr),    /*  mr  Marathi                   0x4e */
   1.817 +    ILCID_POSIX_MAP(ms),    /*  ms  Malay                     0x3e */
   1.818 +    ILCID_POSIX_MAP(mt),    /*  mt  Maltese                   0x3a */
   1.819 +    ILCID_POSIX_MAP(my),    /*  my  Burmese                   0x55 */
   1.820 +/*    ILCID_POSIX_MAP(nb),    //  no  Norwegian                 0x14 */
   1.821 +    ILCID_POSIX_MAP(ne),    /*  ne  Nepali                    0x61 */
   1.822 +    ILCID_POSIX_MAP(nl),    /*  nl  Dutch                     0x13 */
   1.823 +/*    ILCID_POSIX_MAP(nn),    //  no  Norwegian                 0x14 */
   1.824 +    ILCID_POSIX_MAP(no),    /*  *   Norwegian                 0x14 */
   1.825 +    ILCID_POSIX_MAP(nso),   /*  nso Sotho, Northern (Sepedi dialect) 0x6c */
   1.826 +    ILCID_POSIX_MAP(oc),    /*  oc  Occitan                   0x82 */
   1.827 +    ILCID_POSIX_MAP(om),    /*  om  Oromo                     0x72 */
   1.828 +    ILCID_POSIX_MAP(or_IN), /*  or  Oriya                     0x48 */
   1.829 +    ILCID_POSIX_MAP(pa),    /*  pa  Punjabi                   0x46 */
   1.830 +    ILCID_POSIX_MAP(pap),   /*  pap Papiamentu                0x79 */
   1.831 +    ILCID_POSIX_MAP(pl),    /*  pl  Polish                    0x15 */
   1.832 +    ILCID_POSIX_MAP(ps),    /*  ps  Pashto                    0x63 */
   1.833 +    ILCID_POSIX_MAP(pt),    /*  pt  Portuguese                0x16 */
   1.834 +    ILCID_POSIX_MAP(qu),    /*  qu  Quechua                   0x6B */
   1.835 +    ILCID_POSIX_MAP(qut),   /*  qut K'iche                    0x86 */
   1.836 +    ILCID_POSIX_MAP(rm),    /*  rm  Raeto-Romance/Romansh     0x17 */
   1.837 +    ILCID_POSIX_MAP(ro),    /*  ro  Romanian                  0x18 */
   1.838 +    ILCID_POSIX_MAP(root),  /*  root                          0x00 */
   1.839 +    ILCID_POSIX_MAP(ru),    /*  ru  Russian                   0x19 */
   1.840 +    ILCID_POSIX_MAP(rw),    /*  rw  Kinyarwanda               0x87 */
   1.841 +    ILCID_POSIX_MAP(sa),    /*  sa  Sanskrit                  0x4f */
   1.842 +    ILCID_POSIX_MAP(sah),   /*  sah Yakut                     0x85 */
   1.843 +    ILCID_POSIX_MAP(sd),    /*  sd  Sindhi                    0x59 */
   1.844 +    ILCID_POSIX_MAP(se),    /*  se  Sami                      0x3b */
   1.845 +/*    ILCID_POSIX_MAP(sh),    //  sh  Serbo-Croatian            0x1a */
   1.846 +    ILCID_POSIX_MAP(si),    /*  si  Sinhalese                 0x5b */
   1.847 +    ILCID_POSIX_MAP(sk),    /*  sk  Slovak                    0x1b */
   1.848 +    ILCID_POSIX_MAP(sl),    /*  sl  Slovenian                 0x24 */
   1.849 +    ILCID_POSIX_MAP(so),    /*  so  Somali                    0x77 */
   1.850 +    ILCID_POSIX_MAP(sq),    /*  sq  Albanian                  0x1c */
   1.851 +/*    ILCID_POSIX_MAP(sr),    //  sr  Serbian                   0x1a */
   1.852 +    ILCID_POSIX_MAP(st),    /*  st  Sutu                      0x30 */
   1.853 +    ILCID_POSIX_MAP(sv),    /*  sv  Swedish                   0x1d */
   1.854 +    ILCID_POSIX_MAP(sw),    /*  sw  Swahili                   0x41 */
   1.855 +    ILCID_POSIX_MAP(syr),   /*  syr Syriac                    0x5A */
   1.856 +    ILCID_POSIX_MAP(ta),    /*  ta  Tamil                     0x49 */
   1.857 +    ILCID_POSIX_MAP(te),    /*  te  Telugu                    0x4a */
   1.858 +    ILCID_POSIX_MAP(tg),    /*  tg  Tajik                     0x28 */
   1.859 +    ILCID_POSIX_MAP(th),    /*  th  Thai                      0x1e */
   1.860 +    ILCID_POSIX_MAP(ti),    /*  ti  Tigrigna                  0x73 */
   1.861 +    ILCID_POSIX_MAP(tk),    /*  tk  Turkmen                   0x42 */
   1.862 +    ILCID_POSIX_MAP(tn),    /*  tn  Tswana                    0x32 */
   1.863 +    ILCID_POSIX_MAP(tr),    /*  tr  Turkish                   0x1f */
   1.864 +    ILCID_POSIX_MAP(ts),    /*  ts  Tsonga                    0x31 */
   1.865 +    ILCID_POSIX_MAP(tt),    /*  tt  Tatar                     0x44 */
   1.866 +    ILCID_POSIX_MAP(tzm),   /*  tzm Tamazight                 0x5f */
   1.867 +    ILCID_POSIX_MAP(ug),    /*  ug  Uighur                    0x80 */
   1.868 +    ILCID_POSIX_MAP(uk),    /*  uk  Ukrainian                 0x22 */
   1.869 +    ILCID_POSIX_MAP(ur),    /*  ur  Urdu                      0x20 */
   1.870 +    ILCID_POSIX_MAP(uz),    /*  uz  Uzbek                     0x43 */
   1.871 +    ILCID_POSIX_MAP(ve),    /*  ve  Venda                     0x33 */
   1.872 +    ILCID_POSIX_MAP(vi),    /*  vi  Vietnamese                0x2a */
   1.873 +    ILCID_POSIX_MAP(wen),   /*  wen Sorbian                   0x2e */
   1.874 +    ILCID_POSIX_MAP(wo),    /*  wo  Wolof                     0x88 */
   1.875 +    ILCID_POSIX_MAP(xh),    /*  xh  Xhosa                     0x34 */
   1.876 +    ILCID_POSIX_MAP(yi),    /*  yi  Yiddish                   0x3d */
   1.877 +    ILCID_POSIX_MAP(yo),    /*  yo  Yoruba                    0x6a */
   1.878 +    ILCID_POSIX_MAP(zh),    /*  zh  Chinese                   0x04 */
   1.879 +    ILCID_POSIX_MAP(zu),    /*  zu  Zulu                      0x35 */
   1.880 +};
   1.881 +
   1.882 +static const uint32_t gLocaleCount = sizeof(gPosixIDmap)/sizeof(ILcidPosixMap);
   1.883 +
   1.884 +/**
   1.885 + * Do not call this function. It is called by hostID.
   1.886 + * The function is not private because this struct must stay as a C struct,
   1.887 + * and this is an internal class.
   1.888 + */
   1.889 +static int32_t
   1.890 +idCmp(const char* id1, const char* id2)
   1.891 +{
   1.892 +    int32_t diffIdx = 0;
   1.893 +    while (*id1 == *id2 && *id1 != 0) {
   1.894 +        diffIdx++;
   1.895 +        id1++;
   1.896 +        id2++;
   1.897 +    }
   1.898 +    return diffIdx;
   1.899 +}
   1.900 +
   1.901 +/**
   1.902 + * Searches for a Windows LCID
   1.903 + *
   1.904 + * @param posixid the Posix style locale id.
   1.905 + * @param status gets set to U_ILLEGAL_ARGUMENT_ERROR when the Posix ID has
   1.906 + *               no equivalent Windows LCID.
   1.907 + * @return the LCID
   1.908 + */
   1.909 +static uint32_t
   1.910 +getHostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode* status)
   1.911 +{
   1.912 +    int32_t bestIdx = 0;
   1.913 +    int32_t bestIdxDiff = 0;
   1.914 +    int32_t posixIDlen = (int32_t)uprv_strlen(posixID);
   1.915 +    uint32_t idx;
   1.916 +
   1.917 +    for (idx = 0; idx < this_0->numRegions; idx++ ) {
   1.918 +        int32_t sameChars = idCmp(posixID, this_0->regionMaps[idx].posixID);
   1.919 +        if (sameChars > bestIdxDiff && this_0->regionMaps[idx].posixID[sameChars] == 0) {
   1.920 +            if (posixIDlen == sameChars) {
   1.921 +                /* Exact match */
   1.922 +                return this_0->regionMaps[idx].hostID;
   1.923 +            }
   1.924 +            bestIdxDiff = sameChars;
   1.925 +            bestIdx = idx;
   1.926 +        }
   1.927 +    }
   1.928 +    /* We asked for something unusual, like en_ZZ, and we try to return the number for the same language. */
   1.929 +    /* We also have to make sure that sid and si and similar string subsets don't match. */
   1.930 +    if ((posixID[bestIdxDiff] == '_' || posixID[bestIdxDiff] == '@')
   1.931 +        && this_0->regionMaps[bestIdx].posixID[bestIdxDiff] == 0)
   1.932 +    {
   1.933 +        *status = U_USING_FALLBACK_WARNING;
   1.934 +        return this_0->regionMaps[bestIdx].hostID;
   1.935 +    }
   1.936 +
   1.937 +    /*no match found */
   1.938 +    *status = U_ILLEGAL_ARGUMENT_ERROR;
   1.939 +    return this_0->regionMaps->hostID;
   1.940 +}
   1.941 +
   1.942 +static const char*
   1.943 +getPosixID(const ILcidPosixMap *this_0, uint32_t hostID)
   1.944 +{
   1.945 +    uint32_t i;
   1.946 +    for (i = 0; i <= this_0->numRegions; i++)
   1.947 +    {
   1.948 +        if (this_0->regionMaps[i].hostID == hostID)
   1.949 +        {
   1.950 +            return this_0->regionMaps[i].posixID;
   1.951 +        }
   1.952 +    }
   1.953 +
   1.954 +    /* If you get here, then no matching region was found,
   1.955 +       so return the language id with the wild card region. */
   1.956 +    return this_0->regionMaps[0].posixID;
   1.957 +}
   1.958 +
   1.959 +/*
   1.960 +//////////////////////////////////////
   1.961 +//
   1.962 +// LCID --> POSIX
   1.963 +//
   1.964 +/////////////////////////////////////
   1.965 +*/
   1.966 +#ifdef USE_WINDOWS_LOCALE_API
   1.967 +/*
   1.968 + * Various language tags needs to be changed:
   1.969 + * quz -> qu
   1.970 + * prs -> fa
   1.971 + */
   1.972 +#define FIX_LANGUAGE_ID_TAG(buffer, len) \
   1.973 +    if (len >= 3) { \
   1.974 +        if (buffer[0] == 'q' && buffer[1] == 'u' && buffer[2] == 'z') {\
   1.975 +            buffer[2] = 0; \
   1.976 +            uprv_strcat(buffer, buffer+3); \
   1.977 +        } else if (buffer[0] == 'p' && buffer[1] == 'r' && buffer[2] == 's') {\
   1.978 +            buffer[0] = 'f'; buffer[1] = 'a'; buffer[2] = 0; \
   1.979 +            uprv_strcat(buffer, buffer+3); \
   1.980 +        } \
   1.981 +    }
   1.982 +
   1.983 +#endif
   1.984 +U_CAPI int32_t
   1.985 +uprv_convertToPosix(uint32_t hostid, char *posixID, int32_t posixIDCapacity, UErrorCode* status)
   1.986 +{
   1.987 +    uint16_t langID;
   1.988 +    uint32_t localeIndex;
   1.989 +    UBool bLookup = TRUE;
   1.990 +    const char *pPosixID = NULL;
   1.991 +
   1.992 +#ifdef USE_WINDOWS_LOCALE_API
   1.993 +    int32_t tmpLen = 0;
   1.994 +    char locName[157];  /* ULOC_FULLNAME_CAPACITY */
   1.995 +
   1.996 +    tmpLen = GetLocaleInfoA(hostid, LOCALE_SNAME, (LPSTR)locName, sizeof(locName)/sizeof(locName[0]));
   1.997 +    if (tmpLen > 1) {
   1.998 +        /* Windows locale name may contain sorting variant, such as "es-ES_tradnl".
   1.999 +           In such case, we need special mapping data found in the hardcoded table
  1.1000 +           in this source file. */
  1.1001 +        char *p = uprv_strchr(locName, '_');
  1.1002 +        if (p) {
  1.1003 +            /* Keep the base locale, without variant */
  1.1004 +            *p = 0;
  1.1005 +            tmpLen = uprv_strlen(locName);
  1.1006 +        } else {
  1.1007 +            /* No hardcoded table lookup necessary */
  1.1008 +            bLookup = FALSE;
  1.1009 +        }
  1.1010 +        /* Change the tag separator from '-' to '_' */
  1.1011 +        p = locName;
  1.1012 +        while (*p) {
  1.1013 +            if (*p == '-') {
  1.1014 +                *p = '_';
  1.1015 +            }
  1.1016 +            p++;
  1.1017 +        }
  1.1018 +        FIX_LANGUAGE_ID_TAG(locName, tmpLen);
  1.1019 +        pPosixID = locName;
  1.1020 +    }
  1.1021 +#endif
  1.1022 +    if (bLookup) {
  1.1023 +        const char *pCandidate = NULL;
  1.1024 +        langID = LANGUAGE_LCID(hostid);
  1.1025 +
  1.1026 +        for (localeIndex = 0; localeIndex < gLocaleCount; localeIndex++) {
  1.1027 +            if (langID == gPosixIDmap[localeIndex].regionMaps->hostID) {
  1.1028 +                pCandidate = getPosixID(&gPosixIDmap[localeIndex], hostid);
  1.1029 +                break;
  1.1030 +            }
  1.1031 +        }
  1.1032 +
  1.1033 +        /* On Windows, when locale name has a variant, we still look up the hardcoded table.
  1.1034 +           If a match in the hardcoded table is longer than the Windows locale name without
  1.1035 +           variant, we use the one as the result */
  1.1036 +        if (pCandidate && (pPosixID == NULL || uprv_strlen(pCandidate) > uprv_strlen(pPosixID))) {
  1.1037 +            pPosixID = pCandidate;
  1.1038 +        }
  1.1039 +    }
  1.1040 +
  1.1041 +    if (pPosixID) {
  1.1042 +        int32_t resLen = uprv_strlen(pPosixID);
  1.1043 +        int32_t copyLen = resLen <= posixIDCapacity ? resLen : posixIDCapacity;
  1.1044 +        uprv_memcpy(posixID, pPosixID, copyLen);
  1.1045 +        if (resLen < posixIDCapacity) {
  1.1046 +            posixID[resLen] = 0;
  1.1047 +            if (*status == U_STRING_NOT_TERMINATED_WARNING) {
  1.1048 +                *status = U_ZERO_ERROR;
  1.1049 +            }
  1.1050 +        } else if (resLen == posixIDCapacity) {
  1.1051 +            *status = U_STRING_NOT_TERMINATED_WARNING;
  1.1052 +        } else {
  1.1053 +            *status = U_BUFFER_OVERFLOW_ERROR;
  1.1054 +        }
  1.1055 +        return resLen;
  1.1056 +    }
  1.1057 +
  1.1058 +    /* no match found */
  1.1059 +    *status = U_ILLEGAL_ARGUMENT_ERROR;
  1.1060 +    return -1;
  1.1061 +}
  1.1062 +
  1.1063 +/*
  1.1064 +//////////////////////////////////////
  1.1065 +//
  1.1066 +// POSIX --> LCID
  1.1067 +// This should only be called from uloc_getLCID.
  1.1068 +// The locale ID must be in canonical form.
  1.1069 +// langID is separate so that this file doesn't depend on the uloc_* API.
  1.1070 +//
  1.1071 +/////////////////////////////////////
  1.1072 +*/
  1.1073 +
  1.1074 +U_CAPI uint32_t
  1.1075 +uprv_convertToLCID(const char *langID, const char* posixID, UErrorCode* status)
  1.1076 +{
  1.1077 +
  1.1078 +    uint32_t   low    = 0;
  1.1079 +    uint32_t   high   = gLocaleCount;
  1.1080 +    uint32_t   mid;
  1.1081 +    uint32_t   oldmid = 0;
  1.1082 +    int32_t    compVal;
  1.1083 +
  1.1084 +    uint32_t   value         = 0;
  1.1085 +    uint32_t   fallbackValue = (uint32_t)-1;
  1.1086 +    UErrorCode myStatus;
  1.1087 +    uint32_t   idx;
  1.1088 +
  1.1089 +    /* Check for incomplete id. */
  1.1090 +    if (!langID || !posixID || uprv_strlen(langID) < 2 || uprv_strlen(posixID) < 2) {
  1.1091 +        return 0;
  1.1092 +    }
  1.1093 +
  1.1094 +    /*Binary search for the map entry for normal cases */
  1.1095 +
  1.1096 +    while (high > low)  /*binary search*/{
  1.1097 +
  1.1098 +        mid = (high+low) >> 1; /*Finds median*/
  1.1099 +
  1.1100 +        if (mid == oldmid) 
  1.1101 +            break;
  1.1102 +
  1.1103 +        compVal = uprv_strcmp(langID, gPosixIDmap[mid].regionMaps->posixID);
  1.1104 +        if (compVal < 0){
  1.1105 +            high = mid;
  1.1106 +        }
  1.1107 +        else if (compVal > 0){
  1.1108 +            low = mid;
  1.1109 +        }
  1.1110 +        else /*we found it*/{
  1.1111 +            return getHostID(&gPosixIDmap[mid], posixID, status);
  1.1112 +        }
  1.1113 +        oldmid = mid;
  1.1114 +    }
  1.1115 +
  1.1116 +    /*
  1.1117 +     * Sometimes we can't do a binary search on posixID because some LCIDs
  1.1118 +     * go to different locales.  We hit one of those special cases.
  1.1119 +     */
  1.1120 +    for (idx = 0; idx < gLocaleCount; idx++ ) {
  1.1121 +        myStatus = U_ZERO_ERROR;
  1.1122 +        value = getHostID(&gPosixIDmap[idx], posixID, &myStatus);
  1.1123 +        if (myStatus == U_ZERO_ERROR) {
  1.1124 +            return value;
  1.1125 +        }
  1.1126 +        else if (myStatus == U_USING_FALLBACK_WARNING) {
  1.1127 +            fallbackValue = value;
  1.1128 +        }
  1.1129 +    }
  1.1130 +
  1.1131 +    if (fallbackValue != (uint32_t)-1) {
  1.1132 +        *status = U_USING_FALLBACK_WARNING;
  1.1133 +        return fallbackValue;
  1.1134 +    }
  1.1135 +
  1.1136 +    /* no match found */
  1.1137 +    *status = U_ILLEGAL_ARGUMENT_ERROR;
  1.1138 +    return 0;   /* return international (root) */
  1.1139 +}
  1.1140 +

mercurial