1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
25 #include <osl/nlsupport.h>
26 #include <osl/diagnose.h>
27 #include <osl/process.h>
28 #include <rtl/string.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/log.hxx>
32 #include "nlsupport.hxx"
34 // these share a lot, so use one define
35 #if defined(LINUX) || defined(EMSCRIPTEN) || defined(__sun) || \
36 defined(FREEBSD) || defined(OPENBSD) || defined(DRAGONFLY) || defined(NETBSD)
37 #define LO_COMMON_NLS_ARCHS 1
39 #define LO_COMMON_NLS_ARCHS 0
42 #if LO_COMMON_NLS_ARCHS
45 #elif defined(MACOSX) || defined(IOS)
46 #include <osl/module.h>
47 #include <osl/thread.h>
57 const rtl_TextEncoding value
;
62 /*****************************************************************************
63 compare function for binary search
64 *****************************************************************************/
67 pair_compare (const char *key
, const Pair
*pair
)
69 int result
= rtl_str_compareIgnoreAsciiCase( key
, pair
->key
);
73 /*****************************************************************************
74 binary search on encoding tables
75 *****************************************************************************/
78 pair_search (const char *key
, const Pair
*base
, unsigned int member
)
80 unsigned int lower
= 0;
81 unsigned int upper
= member
;
83 /* check for validity of input */
84 if ( (key
== nullptr) || (base
== nullptr) || (member
== 0) )
88 while ( lower
< upper
)
90 const unsigned int current
= (lower
+ upper
) / 2;
91 const int comparison
= pair_compare( key
, base
+ current
);
94 else if (comparison
> 0)
97 return base
+ current
;
103 /*****************************************************************************
104 convert rtl_Locale to locale string
105 *****************************************************************************/
107 static char * compose_locale( rtl_Locale
* pLocale
, char * buffer
, size_t n
)
109 /* check if a valid locale is specified */
110 if( pLocale
&& pLocale
->Language
&&
111 (pLocale
->Language
->length
== 2 || pLocale
->Language
->length
== 3) )
115 /* convert language code to ascii */
117 rtl_String
*pLanguage
= nullptr;
119 rtl_uString2String( &pLanguage
,
120 pLocale
->Language
->buffer
, pLocale
->Language
->length
,
121 RTL_TEXTENCODING_ASCII_US
, OUSTRING_TO_OSTRING_CVTFLAGS
);
123 if( sal::static_int_cast
<sal_uInt32
>(pLanguage
->length
) < n
)
125 strcpy( buffer
, pLanguage
->buffer
);
126 offset
= pLanguage
->length
;
129 rtl_string_release( pLanguage
);
132 /* convert country code to ascii */
133 if( pLocale
->Country
&& (pLocale
->Country
->length
== 2) )
135 rtl_String
*pCountry
= nullptr;
137 rtl_uString2String( &pCountry
,
138 pLocale
->Country
->buffer
, pLocale
->Country
->length
,
139 RTL_TEXTENCODING_ASCII_US
, OUSTRING_TO_OSTRING_CVTFLAGS
);
141 if( offset
+ pCountry
->length
+ 1 < n
)
143 strcpy( buffer
+ offset
++, "_" );
144 strcpy( buffer
+ offset
, pCountry
->buffer
);
145 offset
+= pCountry
->length
;
148 rtl_string_release( pCountry
);
151 /* convert variant to ascii - check if there is enough space for the variant string */
152 if( pLocale
->Variant
&& pLocale
->Variant
->length
&&
153 ( sal::static_int_cast
<sal_uInt32
>(pLocale
->Variant
->length
) < n
- 6 ) )
155 rtl_String
*pVariant
= nullptr;
157 rtl_uString2String( &pVariant
,
158 pLocale
->Variant
->buffer
, pLocale
->Variant
->length
,
159 RTL_TEXTENCODING_ASCII_US
, OUSTRING_TO_OSTRING_CVTFLAGS
);
161 if( offset
+ pVariant
->length
+ 1 < n
)
163 strcpy( buffer
+ offset
, pVariant
->buffer
);
166 rtl_string_release( pVariant
);
175 /*****************************************************************************
176 convert locale string to rtl_Locale
177 *****************************************************************************/
179 static rtl_Locale
* parse_locale( const char * locale
)
181 assert(locale
!= nullptr);
183 if (*locale
== '\0' || std::strcmp(locale
, "C") == 0
184 || std::strcmp(locale
, "POSIX") == 0)
186 return rtl_locale_register(u
"C", u
"", u
"");
189 size_t len
= strlen( locale
);
191 rtl_uString
* pLanguage
= nullptr;
192 rtl_uString
* pCountry
= nullptr;
193 rtl_uString
* pVariant
= nullptr;
195 size_t offset
= std::min
<size_t>(len
, 2);
199 /* language is a two or three letter code */
200 if( (len
> 3 && locale
[3] == '_') || (len
== 3 && locale
[2] != '_') )
203 /* convert language code to unicode */
204 rtl_string2UString( &pLanguage
, locale
, offset
, RTL_TEXTENCODING_ASCII_US
, OSTRING_TO_OUSTRING_CVTFLAGS
);
205 OSL_ASSERT(pLanguage
!= nullptr);
207 /* convert country code to unicode */
208 if( len
>= offset
+3 && locale
[offset
] == '_' )
210 rtl_string2UString( &pCountry
, locale
+ offset
+ 1, 2, RTL_TEXTENCODING_ASCII_US
, OSTRING_TO_OUSTRING_CVTFLAGS
);
211 OSL_ASSERT(pCountry
!= nullptr);
215 /* convert variant code to unicode - do not rely on "." as delimiter */
217 rtl_string2UString( &pVariant
, locale
+ offset
, len
- offset
, RTL_TEXTENCODING_ASCII_US
, OSTRING_TO_OUSTRING_CVTFLAGS
);
218 OSL_ASSERT(pVariant
!= nullptr);
221 ret
= rtl_locale_register( pLanguage
->buffer
, pCountry
? pCountry
->buffer
: u
"", pVariant
? pVariant
->buffer
: u
"" );
223 if (pVariant
) rtl_uString_release(pVariant
);
224 if (pCountry
) rtl_uString_release(pCountry
);
225 if (pLanguage
) rtl_uString_release(pLanguage
);
230 #if LO_COMMON_NLS_ARCHS
233 * This implementation of osl_getTextEncodingFromLocale maps
234 * from nl_langinfo_l(CODESET) to rtl_textencoding defines.
235 * nl_langinfo() is supported only on Linux, Solaris,
236 * >= NetBSD 1.6 and >= FreeBSD 4.4
238 * _nl_language_list[] is an array list of supported encodings. Because
239 * we are using a binary search, the list has to be in ascending order.
240 * We are comparing the encodings case insensitive, so the list has
241 * to be completely upper or lowercase.
246 /* The values in the below list can be obtained with a script like
248 * for i in `locale -a`; do
249 * LC_ALL=$i locale -k code_set_name
252 static const Pair nl_language_list
[] = {
253 { "5601", RTL_TEXTENCODING_EUC_KR
}, /* ko_KR.EUC */
254 { "646", RTL_TEXTENCODING_ISO_8859_1
}, /* fake: ASCII_US */
255 { "ANSI-1251", RTL_TEXTENCODING_MS_1251
}, /* ru_RU.ANSI1251 */
256 { "BIG5", RTL_TEXTENCODING_BIG5
}, /* zh_CN.BIG5 */
257 { "BIG5-HKSCS", RTL_TEXTENCODING_BIG5_HKSCS
}, /* zh_CN.BIG5HK */
258 { "CNS11643", RTL_TEXTENCODING_EUC_TW
}, /* zh_TW.EUC */
259 { "EUCJP", RTL_TEXTENCODING_EUC_JP
}, /* ja_JP.eucjp */
260 { "GB18030", RTL_TEXTENCODING_GB_18030
}, /* zh_CN.GB18030 */
261 { "GB2312", RTL_TEXTENCODING_GB_2312
}, /* zh_CN */
262 { "GBK", RTL_TEXTENCODING_GBK
}, /* zh_CN.GBK */
263 { "ISO8859-1", RTL_TEXTENCODING_ISO_8859_1
},
264 { "ISO8859-10", RTL_TEXTENCODING_ISO_8859_10
},
265 { "ISO8859-13", RTL_TEXTENCODING_ISO_8859_13
}, /* lt_LT lv_LV */
266 { "ISO8859-14", RTL_TEXTENCODING_ISO_8859_14
},
267 { "ISO8859-15", RTL_TEXTENCODING_ISO_8859_15
},
268 { "ISO8859-2", RTL_TEXTENCODING_ISO_8859_2
},
269 { "ISO8859-3", RTL_TEXTENCODING_ISO_8859_3
},
270 { "ISO8859-4", RTL_TEXTENCODING_ISO_8859_4
},
271 { "ISO8859-5", RTL_TEXTENCODING_ISO_8859_5
},
272 { "ISO8859-6", RTL_TEXTENCODING_ISO_8859_6
},
273 { "ISO8859-7", RTL_TEXTENCODING_ISO_8859_7
},
274 { "ISO8859-8", RTL_TEXTENCODING_ISO_8859_8
},
275 { "ISO8859-9", RTL_TEXTENCODING_ISO_8859_9
},
276 { "KOI8-R", RTL_TEXTENCODING_KOI8_R
},
277 { "KOI8-U", RTL_TEXTENCODING_KOI8_U
},
278 { "PCK", RTL_TEXTENCODING_MS_932
},
279 { "SUN_EU_GREEK", RTL_TEXTENCODING_ISO_8859_7
}, /* 8859-7 + Euro */
280 { "TIS620.2533", RTL_TEXTENCODING_MS_874
}, /* th_TH.TIS620 */
281 { "UTF-8", RTL_TEXTENCODING_UTF8
}
284 /* XXX MS-874 is an extension to tis620, so this is not
285 * really equivalent */
287 #elif defined(LINUX) || defined(EMSCRIPTEN)
289 #if !defined(CODESET)
290 #define CODESET _NL_CTYPE_CODESET_NAME
293 const Pair nl_language_list
[] = {
294 { "ANSI_X3.110-1983", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-99 NAPLPS */
295 { "ANSI_X3.4-1968", RTL_TEXTENCODING_ISO_8859_1
}, /* fake: ASCII_US */
296 { "ASMO_449", RTL_TEXTENCODING_DONTKNOW
}, /* ISO_9036 ARABIC7 */
297 { "BALTIC", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-179 */
298 { "BIG5", RTL_TEXTENCODING_BIG5
}, /* locale: zh_TW */
299 { "BIG5-HKSCS", RTL_TEXTENCODING_BIG5_HKSCS
}, /* locale: zh_CN.BIG5HK */
300 { "BIG5HKSCS", RTL_TEXTENCODING_BIG5_HKSCS
}, /* deprecated */
301 { "BS_4730", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-4 ISO646-GB */
302 { "BS_VIEWDATA", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-47 */
303 { "CP1250", RTL_TEXTENCODING_MS_1250
}, /* MS-EE */
304 { "CP1251", RTL_TEXTENCODING_MS_1251
}, /* MS-CYRL */
305 { "CP1252", RTL_TEXTENCODING_MS_1252
}, /* MS-ANSI */
306 { "CP1253", RTL_TEXTENCODING_MS_1253
}, /* MS-GREEK */
307 { "CP1254", RTL_TEXTENCODING_MS_1254
}, /* MS-TURK */
308 { "CP1255", RTL_TEXTENCODING_MS_1255
}, /* MS-HEBR */
309 { "CP1256", RTL_TEXTENCODING_MS_1256
}, /* MS-ARAB */
310 { "CP1257", RTL_TEXTENCODING_MS_1257
}, /* WINBALTRIM */
311 { "CSA_Z243.4-1985-1", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-121 */
312 { "CSA_Z243.4-1985-2", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-122 CSA7-2 */
313 { "CSA_Z243.4-1985-GR", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-123 */
314 { "CSN_369103", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-139 */
315 { "CWI", RTL_TEXTENCODING_DONTKNOW
}, /* CWI-2 CP-HU */
316 { "DEC-MCS", RTL_TEXTENCODING_DONTKNOW
}, /* DEC */
317 { "DIN_66003", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-21 */
318 { "DS_2089", RTL_TEXTENCODING_DONTKNOW
}, /* DS2089 ISO646-DK */
319 { "EBCDIC-AT-DE", RTL_TEXTENCODING_DONTKNOW
},
320 { "EBCDIC-AT-DE-A", RTL_TEXTENCODING_DONTKNOW
},
321 { "EBCDIC-CA-FR", RTL_TEXTENCODING_DONTKNOW
},
322 { "EBCDIC-DK-NO", RTL_TEXTENCODING_DONTKNOW
},
323 { "EBCDIC-DK-NO-A", RTL_TEXTENCODING_DONTKNOW
},
324 { "EBCDIC-ES", RTL_TEXTENCODING_DONTKNOW
},
325 { "EBCDIC-ES-A", RTL_TEXTENCODING_DONTKNOW
},
326 { "EBCDIC-ES-S", RTL_TEXTENCODING_DONTKNOW
},
327 { "EBCDIC-FI-SE", RTL_TEXTENCODING_DONTKNOW
},
328 { "EBCDIC-FI-SE-A", RTL_TEXTENCODING_DONTKNOW
},
329 { "EBCDIC-FR", RTL_TEXTENCODING_DONTKNOW
},
330 { "EBCDIC-IS-FRISS", RTL_TEXTENCODING_DONTKNOW
}, /* FRISS */
331 { "EBCDIC-IT", RTL_TEXTENCODING_DONTKNOW
},
332 { "EBCDIC-PT", RTL_TEXTENCODING_DONTKNOW
},
333 { "EBCDIC-UK", RTL_TEXTENCODING_DONTKNOW
},
334 { "EBCDIC-US", RTL_TEXTENCODING_DONTKNOW
},
335 { "ECMA-CYRILLIC", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-111 */
336 { "ES", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-17 */
337 { "ES2", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-85 */
338 { "EUC-JP", RTL_TEXTENCODING_EUC_JP
}, /* locale: ja_JP.eucjp */
339 { "EUC-KR", RTL_TEXTENCODING_EUC_KR
}, /* locale: ko_KR.euckr */
340 { "EUC-TW", RTL_TEXTENCODING_EUC_TW
}, /* locale: zh_TW.euctw */
341 { "GB18030", RTL_TEXTENCODING_GB_18030
}, /* locale: zh_CN.gb18030 */
342 { "GB2312", RTL_TEXTENCODING_GB_2312
}, /* locale: zh_CN */
343 { "GB_1988-80", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-57 */
344 { "GBK", RTL_TEXTENCODING_GBK
}, /* locale: zh_CN.GBK */
345 { "GOST_19768-74", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-153 */
346 { "GREEK-CCITT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-150 */
347 { "GREEK7", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-88 */
348 { "GREEK7-OLD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-18 */
349 { "HP-ROMAN8", RTL_TEXTENCODING_DONTKNOW
}, /* ROMAN8 R8 */
350 { "IBM037", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-[US|CA|WT] */
351 { "IBM038", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-INT CP038 */
352 { "IBM1004", RTL_TEXTENCODING_DONTKNOW
}, /* CP1004 OS2LATIN1 */
353 { "IBM1026", RTL_TEXTENCODING_DONTKNOW
}, /* CP1026 1026 */
354 { "IBM1047", RTL_TEXTENCODING_DONTKNOW
}, /* CP1047 1047 */
355 { "IBM256", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-INT1 */
356 { "IBM273", RTL_TEXTENCODING_DONTKNOW
}, /* CP273 */
357 { "IBM274", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-BE CP274 */
358 { "IBM275", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-BR CP275 */
359 { "IBM277", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CP-[DK|NO] */
360 { "IBM278", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CP-[FISE]*/
361 { "IBM280", RTL_TEXTENCODING_DONTKNOW
}, /* CP280 EBCDIC-CP-IT*/
362 { "IBM281", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-JP-E CP281 */
363 { "IBM284", RTL_TEXTENCODING_DONTKNOW
}, /* CP284 EBCDIC-CP-ES */
364 { "IBM285", RTL_TEXTENCODING_DONTKNOW
}, /* CP285 EBCDIC-CP-GB */
365 { "IBM290", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-JP-KANA */
366 { "IBM297", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CP-FR */
367 { "IBM420", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CP-AR1 */
368 { "IBM423", RTL_TEXTENCODING_DONTKNOW
}, /* CP423 EBCDIC-CP-GR */
369 { "IBM424", RTL_TEXTENCODING_DONTKNOW
}, /* CP424 EBCDIC-CP-HE */
370 { "IBM437", RTL_TEXTENCODING_IBM_437
}, /* CP437 437 */
371 { "IBM500", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CP-[BE|CH] */
372 { "IBM850", RTL_TEXTENCODING_IBM_850
}, /* CP850 850 */
373 { "IBM851", RTL_TEXTENCODING_DONTKNOW
}, /* CP851 851 */
374 { "IBM852", RTL_TEXTENCODING_IBM_852
}, /* CP852 852 */
375 { "IBM855", RTL_TEXTENCODING_IBM_855
}, /* CP855 855 */
376 { "IBM857", RTL_TEXTENCODING_IBM_857
}, /* CP857 857 */
377 { "IBM860", RTL_TEXTENCODING_IBM_860
}, /* CP860 860 */
378 { "IBM861", RTL_TEXTENCODING_IBM_861
}, /* CP861 861 CP-IS */
379 { "IBM862", RTL_TEXTENCODING_IBM_862
}, /* CP862 862 */
380 { "IBM863", RTL_TEXTENCODING_IBM_863
}, /* CP863 863 */
381 { "IBM864", RTL_TEXTENCODING_IBM_864
}, /* CP864 */
382 { "IBM865", RTL_TEXTENCODING_IBM_865
}, /* CP865 865 */
383 { "IBM866", RTL_TEXTENCODING_IBM_866
}, /* CP866 866 */
384 { "IBM868", RTL_TEXTENCODING_DONTKNOW
}, /* CP868 CP-AR */
385 { "IBM869", RTL_TEXTENCODING_IBM_869
}, /* CP869 869 CP-GR */
386 { "IBM870", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-[ROECE|YU] */
387 { "IBM871", RTL_TEXTENCODING_DONTKNOW
}, /* CP871 EBCDIC-CP-IS */
388 { "IBM875", RTL_TEXTENCODING_DONTKNOW
}, /* CP875 EBCDIC-GREEK */
389 { "IBM880", RTL_TEXTENCODING_DONTKNOW
}, /* EBCDIC-CYRILLIC */
390 { "IBM891", RTL_TEXTENCODING_DONTKNOW
}, /* CP891 */
391 { "IBM903", RTL_TEXTENCODING_DONTKNOW
}, /* CP903 */
392 { "IBM904", RTL_TEXTENCODING_DONTKNOW
}, /* CP904 904 */
393 { "IBM905", RTL_TEXTENCODING_DONTKNOW
}, /* CP905 EBCDIC-CP-TR */
394 { "IBM918", RTL_TEXTENCODING_DONTKNOW
}, /* CP918 EBCDIC-AR2 */
395 { "IEC_P27-1", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-143 */
396 { "INIS", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-49 */
397 { "INIS-8", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-50 */
398 { "INIS-CYRILLIC", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-51 */
399 { "INVARIANT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-170 */
400 { "ISO-8859-1", RTL_TEXTENCODING_ISO_8859_1
}, /* ISO-IR-100 CP819 */
401 { "ISO-8859-10", RTL_TEXTENCODING_ISO_8859_10
}, /* ISO-IR-157 LATIN6 */
402 { "ISO-8859-13", RTL_TEXTENCODING_ISO_8859_13
}, /* ISO-IR-179 LATIN7 */
403 { "ISO-8859-14", RTL_TEXTENCODING_ISO_8859_14
}, /* LATIN8 L8 */
404 { "ISO-8859-15", RTL_TEXTENCODING_ISO_8859_15
},
405 { "ISO-8859-2", RTL_TEXTENCODING_ISO_8859_2
}, /* LATIN2 L2 */
406 { "ISO-8859-3", RTL_TEXTENCODING_ISO_8859_3
}, /* LATIN3 L3 */
407 { "ISO-8859-4", RTL_TEXTENCODING_ISO_8859_4
}, /* LATIN4 L4 */
408 { "ISO-8859-5", RTL_TEXTENCODING_ISO_8859_5
}, /* CYRILLIC */
409 { "ISO-8859-6", RTL_TEXTENCODING_ISO_8859_6
}, /* ECMA-114 ARABIC */
410 { "ISO-8859-7", RTL_TEXTENCODING_ISO_8859_7
}, /* ECMA-118 GREEK8 */
411 { "ISO-8859-8", RTL_TEXTENCODING_ISO_8859_8
}, /* ISO_8859-8 HEBREW */
412 { "ISO-8859-9", RTL_TEXTENCODING_ISO_8859_9
}, /* ISO_8859-9 LATIN5 */
413 { "ISO-IR-90", RTL_TEXTENCODING_DONTKNOW
}, /* ISO_6937-2:1983 */
414 { "ISO_10367-BOX", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-155 */
415 { "ISO_2033-1983", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-98 E13B */
416 { "ISO_5427", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-37 KOI-7 */
417 { "ISO_5427-EXT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-54 */
418 { "ISO_5428", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-55 */
419 { "ISO_646.BASIC", RTL_TEXTENCODING_ASCII_US
}, /* REF */
420 { "ISO_646.IRV", RTL_TEXTENCODING_ASCII_US
}, /* ISO-IR-2 IRV */
421 { "ISO_646.IRV:1983", RTL_TEXTENCODING_ISO_8859_1
}, /* fake: ASCII_US, used for "C" locale*/
422 { "ISO_6937", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-156 ISO6937*/
423 { "ISO_6937-2-25", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-152 */
424 { "ISO_6937-2-ADD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-142 */
425 { "ISO_8859-SUPP", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-154 */
426 { "IT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-15 */
427 { "JIS_C6220-1969-JP", RTL_TEXTENCODING_DONTKNOW
}, /* KATAKANA X0201-7 */
428 { "JIS_C6220-1969-RO", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-14 */
429 { "JIS_C6229-1984-A", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-91 */
430 { "JIS_C6229-1984-B", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-92 */
431 { "JIS_C6229-1984-B-ADD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-93 */
432 { "JIS_C6229-1984-HAND", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-94 */
433 { "JIS_C6229-1984-HAND-ADD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-95 */
434 { "JIS_C6229-1984-KANA", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-96 */
435 { "JIS_X0201", RTL_TEXTENCODING_DONTKNOW
}, /* X0201 */
436 { "JUS_I.B1.002", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-141 */
437 { "JUS_I.B1.003-MAC", RTL_TEXTENCODING_DONTKNOW
}, /* MACEDONIAN */
438 { "JUS_I.B1.003-SERB", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-146 SERBIAN */
439 { "KOI-8", RTL_TEXTENCODING_DONTKNOW
},
440 { "KOI8-R", RTL_TEXTENCODING_KOI8_R
},
441 { "KOI8-U", RTL_TEXTENCODING_KOI8_U
},
442 { "KSC5636", RTL_TEXTENCODING_DONTKNOW
}, /* ISO646-KR */
443 { "LATIN-GREEK", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-19 */
444 { "LATIN-GREEK-1", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-27 */
445 { "MAC-IS", RTL_TEXTENCODING_APPLE_ROMAN
},
446 { "MAC-UK", RTL_TEXTENCODING_APPLE_ROMAN
},
447 { "MACINTOSH", RTL_TEXTENCODING_APPLE_ROMAN
}, /* MAC */
448 { "MSZ_7795.3", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-86 */
449 { "NATS-DANO", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-9-1 */
450 { "NATS-DANO-ADD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-9-2 */
451 { "NATS-SEFI", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-8-1 */
452 { "NATS-SEFI-ADD", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-8-2 */
453 { "NC_NC00-10", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-151 */
454 { "NEXTSTEP", RTL_TEXTENCODING_DONTKNOW
}, /* NEXT */
455 { "NF_Z_62-010", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-69 */
456 { "NF_Z_62-010_(1973)", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-25 */
457 { "NS_4551-1", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-60 */
458 { "NS_4551-2", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-61 */
459 { "PT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-16 */
460 { "PT2", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-84 */
461 { "SAMI", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-158 */
462 { "SEN_850200_B", RTL_TEXTENCODING_DONTKNOW
}, /* ISO646-[FI|SE] */
463 { "SEN_850200_C", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-11 */
464 { "T.101-G2", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-128 */
465 { "T.61-7BIT", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-102 */
466 { "T.61-8BIT", RTL_TEXTENCODING_DONTKNOW
}, /* T.61 ISO-IR-103 */
467 { "TIS-620", RTL_TEXTENCODING_MS_874
}, /* locale: th_TH */
468 { "UTF-8", RTL_TEXTENCODING_UTF8
}, /* ISO-10646/UTF-8 */
469 { "VIDEOTEX-SUPPL", RTL_TEXTENCODING_DONTKNOW
}, /* ISO-IR-70 */
470 { "WIN-SAMI-2", RTL_TEXTENCODING_DONTKNOW
} /* WS2 */
473 #elif defined(FREEBSD) || defined(DRAGONFLY)
475 static const Pair nl_language_list
[] = {
476 { "ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
477 { "BIG5", RTL_TEXTENCODING_BIG5
}, /* China - Traditional Chinese */
478 { "CP1251", RTL_TEXTENCODING_MS_1251
}, /* MS-CYRL */
479 { "CP866", RTL_TEXTENCODING_IBM_866
}, /* CP866 866 */
480 { "EUCCN", RTL_TEXTENCODING_EUC_CN
}, /* China - Simplified Chinese */
481 { "EUCJP", RTL_TEXTENCODING_EUC_JP
}, /* Japan */
482 { "EUCKR", RTL_TEXTENCODING_EUC_KR
}, /* Korea */
483 { "ISO8859-1", RTL_TEXTENCODING_ISO_8859_1
}, /* Western */
484 { "ISO8859-15", RTL_TEXTENCODING_ISO_8859_15
}, /* Western Updated (w/Euro sign) */
485 { "ISO8859-2", RTL_TEXTENCODING_ISO_8859_2
}, /* Central European */
486 { "ISO8859-4", RTL_TEXTENCODING_ISO_8859_4
}, /* LATIN4 L4 */
487 { "ISO8859-5", RTL_TEXTENCODING_ISO_8859_5
}, /* Cyrillic */
488 { "ISO8859-7", RTL_TEXTENCODING_ISO_8859_7
}, /* Greek */
489 { "ISO8859-9", RTL_TEXTENCODING_ISO_8859_9
}, /* Turkish */
490 { "KOI8-R", RTL_TEXTENCODING_KOI8_R
}, /* KOI8-R */
491 { "KOI8-U", RTL_TEXTENCODING_KOI8_U
}, /* KOI8-U */
492 { "SJIS", RTL_TEXTENCODING_SHIFT_JIS
}, /* Japan */
493 { "US-ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
494 { "UTF-8", RTL_TEXTENCODING_UTF8
} /* ISO-10646/UTF-8 */
497 #elif defined(NETBSD)
499 static const Pair nl_language_list
[] = {
500 { "ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
501 { "BIG5", RTL_TEXTENCODING_BIG5
}, /* China - Traditional Chinese */
502 { "Big5", RTL_TEXTENCODING_BIG5
}, /* China - Traditional Chinese */
503 { "Big5-HKSCS", RTL_TEXTENCODING_BIG5_HKSCS
}, /* locale: zh_CN.BIG5HK */
504 { "Big5HKSCS", RTL_TEXTENCODING_BIG5_HKSCS
}, /* deprecated */
505 { "CP1251", RTL_TEXTENCODING_MS_1251
}, /* MS-CYRL */
506 { "CP866", RTL_TEXTENCODING_IBM_866
}, /* CP866 866 */
507 { "CTEXT", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
508 { "eucCN", RTL_TEXTENCODING_EUC_CN
}, /* China - Simplified Chinese */
509 { "eucJP", RTL_TEXTENCODING_EUC_JP
}, /* Japan */
510 { "eucKR", RTL_TEXTENCODING_EUC_KR
}, /* Korea */
511 { "eucTW", RTL_TEXTENCODING_EUC_TW
}, /* China - Traditional Chinese */
512 { "GB18030", RTL_TEXTENCODING_GB_18030
}, /* locale: zh_CN.gb18030 */
513 { "GB2312", RTL_TEXTENCODING_GB_2312
}, /* locale: zh_CN */
514 { "ISO-2022-JP", RTL_TEXTENCODING_DONTKNOW
}, /* */
515 { "ISO-2022-JP-2", RTL_TEXTENCODING_DONTKNOW
}, /* */
516 { "ISO8859-1", RTL_TEXTENCODING_ISO_8859_1
}, /* Western */
517 { "ISO8859-13", RTL_TEXTENCODING_ISO_8859_13
}, /* ISO-IR-179 LATIN7 */
518 { "ISO8859-15", RTL_TEXTENCODING_ISO_8859_15
}, /* Western Updated (w/Euro sign) */
519 { "ISO8859-2", RTL_TEXTENCODING_ISO_8859_2
}, /* Central European */
520 { "ISO8859-4", RTL_TEXTENCODING_ISO_8859_4
}, /* LATIN4 L4 */
521 { "ISO8859-5", RTL_TEXTENCODING_ISO_8859_5
}, /* Cyrillic */
522 { "ISO8859-7", RTL_TEXTENCODING_ISO_8859_7
}, /* Greek */
523 { "ISO8859-9", RTL_TEXTENCODING_ISO_8859_9
}, /* Turkish */
524 { "KOI8-R", RTL_TEXTENCODING_KOI8_R
}, /* KOI8-R */
525 { "KOI8-U", RTL_TEXTENCODING_KOI8_U
}, /* KOI8-U */
526 { "PT154", RTL_TEXTENCODING_PT154
}, /* */
527 { "SJIS", RTL_TEXTENCODING_SHIFT_JIS
}, /* Japan */
528 { "US-ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
529 { "UTF-8", RTL_TEXTENCODING_UTF8
} /* ISO-10646/UTF-8 */
532 #elif defined(OPENBSD)
534 static const Pair nl_language_list
[] = {
535 { "ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
536 { "BIG5", RTL_TEXTENCODING_BIG5
}, /* China - Traditional Chinese */
537 { "CP1251", RTL_TEXTENCODING_MS_1251
}, /* MS-CYRL */
538 { "CP866", RTL_TEXTENCODING_IBM_866
}, /* CP866 866 */
539 { "EUCCN", RTL_TEXTENCODING_EUC_CN
}, /* China - Simplified Chinese */
540 { "EUCJP", RTL_TEXTENCODING_EUC_JP
}, /* Japan */
541 { "EUCKR", RTL_TEXTENCODING_EUC_KR
}, /* Korea */
542 { "ISO8859-1", RTL_TEXTENCODING_ISO_8859_1
}, /* Western */
543 { "ISO8859-15", RTL_TEXTENCODING_ISO_8859_15
}, /* Western Updated (w/Euro sign) */
544 { "ISO8859-2", RTL_TEXTENCODING_ISO_8859_2
}, /* Central European */
545 { "ISO8859-4", RTL_TEXTENCODING_ISO_8859_4
}, /* LATIN4 L4 */
546 { "ISO8859-5", RTL_TEXTENCODING_ISO_8859_5
}, /* Cyrillic */
547 { "ISO8859-7", RTL_TEXTENCODING_ISO_8859_7
}, /* Greek */
548 { "ISO8859-9", RTL_TEXTENCODING_ISO_8859_9
}, /* Turkish */
549 { "KOI8-R", RTL_TEXTENCODING_KOI8_R
}, /* KOI8-R */
550 { "KOI8-U", RTL_TEXTENCODING_KOI8_U
}, /* KOI8-U */
551 { "SJIS", RTL_TEXTENCODING_SHIFT_JIS
}, /* Japan */
552 { "US-ASCII", RTL_TEXTENCODING_ASCII_US
}, /* US-ASCII */
553 { "UTF-8", RTL_TEXTENCODING_UTF8
} /* ISO-10646/UTF-8 */
557 #error Unhandled individual LO_COMMON_NLS_ARCHS
558 #endif // individual common NLS archs
560 /*****************************************************************************
561 return the text encoding corresponding to the given locale
562 *****************************************************************************/
564 rtl_TextEncoding
osl_getTextEncodingFromLocale( rtl_Locale
* pLocale
)
566 const Pair
*language
=nullptr;
568 char locale_buf
[64] = "";
569 char codeset_buf
[64];
571 char *codeset
= nullptr;
573 /* default to process locale if pLocale == NULL */
574 if( pLocale
== nullptr )
575 osl_getProcessLocale( &pLocale
);
577 /* convert rtl_Locale to locale string */
578 compose_locale( pLocale
, locale_buf
, 64 );
580 locale_t ctype_locale
= newlocale(
581 LC_CTYPE_MASK
, locale_buf
, static_cast<locale_t
>(0));
582 if (ctype_locale
== static_cast<locale_t
>(0))
584 return RTL_TEXTENCODING_DONTKNOW
;
587 /* get the charset as indicated by the LC_CTYPE locale */
588 #if defined(NETBSD) && !defined(CODESET)
591 codeset
= nl_langinfo_l(CODESET
, ctype_locale
);
592 // per SUSv4, the return value of nl_langinfo_l can be invalidated by a
593 // subsequent call to nl_langinfo (not nl_langinfo_l) in any thread, but
594 // we cannot guard against that (at least, no code in LO itself should
598 if ( codeset
!= nullptr )
600 /* get codeset into mt save memory */
601 strncpy( codeset_buf
, codeset
, sizeof(codeset_buf
) );
602 codeset_buf
[sizeof(codeset_buf
) - 1] = 0;
603 codeset
= codeset_buf
;
606 freelocale(ctype_locale
);
608 /* search the codeset in our language list */
609 if ( codeset
!= nullptr )
611 language
= pair_search (codeset
, nl_language_list
, SAL_N_ELEMENTS( nl_language_list
) );
614 OSL_ASSERT( language
&& ( RTL_TEXTENCODING_DONTKNOW
!= language
->value
) );
616 /* a matching item in our list provides a mapping from codeset to
618 if ( language
!= nullptr )
619 return language
->value
;
621 return RTL_TEXTENCODING_DONTKNOW
;
624 /*****************************************************************************
625 return the current process locale
626 *****************************************************************************/
628 void imp_getProcessLocale( rtl_Locale
** ppLocale
)
630 char const * locale
= getenv("LC_ALL");
631 if (locale
== nullptr || *locale
== '\0') {
632 locale
= getenv("LC_CTYPE");
633 if (locale
== nullptr || *locale
== '\0') {
634 locale
= getenv("LANG");
635 if (locale
== nullptr || *locale
== '\0') {
640 // coverity[overrun-buffer-val : FALSE] - coverity gets this very wrong
641 *ppLocale
= parse_locale(locale
);
644 #else // !LO_COMMON_NLS_ARCHS
647 * This implementation of osl_getTextEncodingFromLocale maps
648 * from the ISO language codes.
651 const Pair full_locale_list
[] = {
652 { "ja_JP.eucJP", RTL_TEXTENCODING_EUC_JP
},
653 { "ja_JP.EUC", RTL_TEXTENCODING_EUC_JP
},
654 { "ko_KR.EUC", RTL_TEXTENCODING_EUC_KR
},
655 { "zh_CN.EUC", RTL_TEXTENCODING_EUC_CN
},
656 { "zh_TW.EUC", RTL_TEXTENCODING_EUC_TW
}
659 const Pair locale_extension_list
[] = {
660 { "big5", RTL_TEXTENCODING_BIG5
},
661 { "big5hk", RTL_TEXTENCODING_BIG5_HKSCS
},
662 { "gb18030", RTL_TEXTENCODING_GB_18030
},
663 { "euc", RTL_TEXTENCODING_EUC_JP
},
664 { "iso8859-1", RTL_TEXTENCODING_ISO_8859_1
},
665 { "iso8859-10", RTL_TEXTENCODING_ISO_8859_10
},
666 { "iso8859-13", RTL_TEXTENCODING_ISO_8859_13
},
667 { "iso8859-14", RTL_TEXTENCODING_ISO_8859_14
},
668 { "iso8859-15", RTL_TEXTENCODING_ISO_8859_15
},
669 { "iso8859-2", RTL_TEXTENCODING_ISO_8859_2
},
670 { "iso8859-3", RTL_TEXTENCODING_ISO_8859_3
},
671 { "iso8859-4", RTL_TEXTENCODING_ISO_8859_4
},
672 { "iso8859-5", RTL_TEXTENCODING_ISO_8859_5
},
673 { "iso8859-6", RTL_TEXTENCODING_ISO_8859_6
},
674 { "iso8859-7", RTL_TEXTENCODING_ISO_8859_7
},
675 { "iso8859-8", RTL_TEXTENCODING_ISO_8859_8
},
676 { "iso8859-9", RTL_TEXTENCODING_ISO_8859_9
},
677 { "koi8-r", RTL_TEXTENCODING_KOI8_R
},
678 { "koi8-u", RTL_TEXTENCODING_KOI8_U
},
679 { "pck", RTL_TEXTENCODING_MS_932
},
681 { "sun_eu_greek", RTL_TEXTENCODING_DONTKNOW
},
683 { "utf-16", RTL_TEXTENCODING_UNICODE
},
684 { "utf-7", RTL_TEXTENCODING_UTF7
},
685 { "utf-8", RTL_TEXTENCODING_UTF8
}
688 const Pair iso_language_list
[] = {
689 { "af", RTL_TEXTENCODING_ISO_8859_1
},
690 { "ar", RTL_TEXTENCODING_ISO_8859_6
},
691 { "az", RTL_TEXTENCODING_ISO_8859_9
},
692 { "be", RTL_TEXTENCODING_ISO_8859_5
},
693 { "bg", RTL_TEXTENCODING_ISO_8859_5
},
694 { "ca", RTL_TEXTENCODING_ISO_8859_1
},
695 { "cs", RTL_TEXTENCODING_ISO_8859_2
},
696 { "da", RTL_TEXTENCODING_ISO_8859_1
},
697 { "de", RTL_TEXTENCODING_ISO_8859_1
},
698 { "el", RTL_TEXTENCODING_ISO_8859_7
},
699 { "en", RTL_TEXTENCODING_ISO_8859_1
},
700 { "es", RTL_TEXTENCODING_ISO_8859_1
},
701 { "et", RTL_TEXTENCODING_ISO_8859_4
},
702 { "eu", RTL_TEXTENCODING_ISO_8859_1
},
703 { "fa", RTL_TEXTENCODING_ISO_8859_6
},
704 { "fi", RTL_TEXTENCODING_ISO_8859_1
},
705 { "fo", RTL_TEXTENCODING_ISO_8859_1
},
706 { "fr", RTL_TEXTENCODING_ISO_8859_1
},
707 { "gr", RTL_TEXTENCODING_ISO_8859_7
},
708 { "he", RTL_TEXTENCODING_ISO_8859_8
},
709 { "hi", RTL_TEXTENCODING_DONTKNOW
},
710 { "hr", RTL_TEXTENCODING_ISO_8859_2
},
711 { "hu", RTL_TEXTENCODING_ISO_8859_2
},
712 { "hy", RTL_TEXTENCODING_DONTKNOW
},
713 { "id", RTL_TEXTENCODING_ISO_8859_1
},
714 { "is", RTL_TEXTENCODING_ISO_8859_1
},
715 { "it", RTL_TEXTENCODING_ISO_8859_1
},
716 { "iw", RTL_TEXTENCODING_ISO_8859_8
},
717 { "ja", RTL_TEXTENCODING_EUC_JP
},
718 { "ka", RTL_TEXTENCODING_DONTKNOW
},
719 { "kk", RTL_TEXTENCODING_ISO_8859_5
},
720 { "ko", RTL_TEXTENCODING_EUC_KR
},
721 { "lt", RTL_TEXTENCODING_ISO_8859_4
},
722 { "lv", RTL_TEXTENCODING_ISO_8859_4
},
723 { "mk", RTL_TEXTENCODING_ISO_8859_5
},
724 { "mr", RTL_TEXTENCODING_DONTKNOW
},
725 { "ms", RTL_TEXTENCODING_ISO_8859_1
},
726 { "nl", RTL_TEXTENCODING_ISO_8859_1
},
727 { "no", RTL_TEXTENCODING_ISO_8859_1
},
728 { "pl", RTL_TEXTENCODING_ISO_8859_2
},
729 { "pt", RTL_TEXTENCODING_ISO_8859_1
},
730 { "ro", RTL_TEXTENCODING_ISO_8859_2
},
731 { "ru", RTL_TEXTENCODING_ISO_8859_5
},
732 { "sa", RTL_TEXTENCODING_DONTKNOW
},
733 { "sk", RTL_TEXTENCODING_ISO_8859_2
},
734 { "sl", RTL_TEXTENCODING_ISO_8859_2
},
735 { "sq", RTL_TEXTENCODING_ISO_8859_2
},
736 { "sv", RTL_TEXTENCODING_ISO_8859_1
},
737 { "sw", RTL_TEXTENCODING_ISO_8859_1
},
738 { "ta", RTL_TEXTENCODING_DONTKNOW
},
739 { "th", RTL_TEXTENCODING_DONTKNOW
},
740 { "tr", RTL_TEXTENCODING_ISO_8859_9
},
741 { "tt", RTL_TEXTENCODING_ISO_8859_5
},
742 { "uk", RTL_TEXTENCODING_ISO_8859_5
},
743 { "ur", RTL_TEXTENCODING_ISO_8859_6
},
744 { "uz", RTL_TEXTENCODING_ISO_8859_9
},
745 { "vi", RTL_TEXTENCODING_DONTKNOW
},
746 { "zh", RTL_TEXTENCODING_BIG5
}
749 /*****************************************************************************
750 return the text encoding corresponding to the given locale
751 *****************************************************************************/
753 rtl_TextEncoding
osl_getTextEncodingFromLocale( rtl_Locale
* pLocale
)
755 const Pair
*language
= nullptr;
756 char locale_buf
[64] = "";
758 /* default to process locale if pLocale == NULL */
759 if( nullptr == pLocale
)
760 osl_getProcessLocale( &pLocale
);
762 /* convert rtl_Locale to locale string */
763 if( compose_locale( pLocale
, locale_buf
, 64 ) )
765 /* check special handling list (EUC) first */
766 language
= pair_search( locale_buf
, full_locale_list
, SAL_N_ELEMENTS( full_locale_list
) );
768 if( nullptr == language
)
771 * check if there is a charset qualifier at the end of the given locale string
772 * e.g. de.ISO8859-15 or de.ISO8859-15@euro which strongly indicates what
775 char* cp
= strrchr( locale_buf
, '.' );
779 language
= pair_search( cp
+ 1, locale_extension_list
, SAL_N_ELEMENTS( locale_extension_list
) );
783 /* use iso language code to determine the charset */
784 if( nullptr == language
)
786 /* iso lang codes have 2 characters */
787 locale_buf
[2] = '\0';
789 language
= pair_search( locale_buf
, iso_language_list
, SAL_N_ELEMENTS( iso_language_list
) );
793 /* a matching item in our list provides a mapping from codeset to
795 if ( language
!= nullptr )
796 return language
->value
;
798 return RTL_TEXTENCODING_DONTKNOW
;
801 #if defined(MACOSX) || defined(IOS)
803 /*****************************************************************************
804 return the current process locale
805 *****************************************************************************/
807 void imp_getProcessLocale( rtl_Locale
** ppLocale
)
809 OUString
loc16(macosx_getLocale());
811 if (!loc16
.convertToString(
812 &locale
, RTL_TEXTENCODING_UTF8
,
813 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
814 | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)))
816 SAL_INFO("sal.osl", "Cannot convert \"" << loc16
<< "\" to UTF-8");
819 /* handle the case where OS specific method of finding locale fails */
820 if ( locale
.isEmpty() )
822 /* simulate behavior of setlocale */
823 locale
= getenv( "LC_ALL" );
825 if( locale
.isEmpty() )
826 locale
= getenv( "LC_CTYPE" );
828 if( locale
.isEmpty() )
829 locale
= getenv( "LANG" );
831 if( locale
.isEmpty() )
835 /* return the locale */
836 *ppLocale
= parse_locale( locale
.getStr() );
839 #else // !MACOSX && !IOS
841 /*****************************************************************************
842 return the current process locale
843 *****************************************************************************/
845 void imp_getProcessLocale( rtl_Locale
** ppLocale
)
848 /* No locale environment variables on Android, so why even bother
851 const char* locale
= "en-US.UTF-8";
853 /* simulate behavior off setlocale */
854 const char* locale
= getenv("LC_ALL");
857 locale
= getenv( "LC_CTYPE" );
860 locale
= getenv( "LANG" );
866 *ppLocale
= parse_locale( locale
);
869 #endif // !MACOSX && !IOS
870 #endif // !LO_COMMON_NLS_ARCHS
872 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */