merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / textenc / tencinfo.c
blob30a2fef0da720f72199c936680d605a65a197ce0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "rtl/tencinfo.h"
29 #include "gettextencodingdata.h"
30 #include "tenchelp.h"
32 #ifndef _RTL_ALLOC_H
33 #include "rtl/alloc.h"
34 #endif
36 #ifndef INCLUDED_STDDEF_H
37 #include <stddef.h>
38 #define INCLUDED_STDDEF_H
39 #endif
40 #ifndef INCLUDED_STRING_H
41 #include <string.h>
42 #define INCLUDED_STRING_H
43 #endif
45 sal_Bool SAL_CALL rtl_isOctetTextEncoding(rtl_TextEncoding nEncoding)
47 return (sal_Bool)
48 (nEncoding > RTL_TEXTENCODING_DONTKNOW
49 && (nEncoding <= RTL_TEXTENCODING_ADOBE_DINGBATS)
50 /* always update this! */
51 && nEncoding != 9); /* RTL_TEXTENCODING_SYSTEM */
54 /* ======================================================================= */
56 static void Impl_toAsciiLower( const sal_Char* pName, sal_Char* pBuf )
58 while ( *pName )
60 /* A-Z */
61 if ( (*pName >= 0x41) && (*pName <= 0x5A) )
62 *pBuf = (*pName)+0x20; /* toAsciiLower */
63 else
64 *pBuf = *pName;
66 pBuf++;
67 pName++;
70 *pBuf = '\0';
73 /* ----------------------------------------------------------------------- */
75 static void Impl_toAsciiLowerAndRemoveNonAlphanumeric( const sal_Char* pName, sal_Char* pBuf )
77 while ( *pName )
79 /* A-Z */
80 if ( (*pName >= 0x41) && (*pName <= 0x5A) )
82 *pBuf = (*pName)+0x20; /* toAsciiLower */
83 pBuf++;
85 /* a-z, 0-9 */
86 else if ( ((*pName >= 0x61) && (*pName <= 0x7A)) ||
87 ((*pName >= 0x30) && (*pName <= 0x39)) )
89 *pBuf = *pName;
90 pBuf++;
93 pName++;
96 *pBuf = '\0';
99 /* ----------------------------------------------------------------------- */
101 /* pMatchStr must match with all characters in pCompStr */
102 static sal_Bool Impl_matchString( const sal_Char* pCompStr, const sal_Char* pMatchStr )
104 /* We test only for end in MatchStr, because the last 0 character from */
105 /* pCompStr is unequal a character in MatchStr, so the loop terminates */
106 while ( *pMatchStr )
108 if ( *pCompStr != *pMatchStr )
109 return sal_False;
111 pCompStr++;
112 pMatchStr++;
115 return sal_True;
118 /* ======================================================================= */
120 typedef struct
122 const sal_Char* mpCharsetStr;
123 rtl_TextEncoding meTextEncoding;
124 } ImplStrCharsetDef;
126 typedef struct
128 const sal_Char* mpCharsetStr;
129 const ImplStrCharsetDef* mpSecondPartTab;
130 } ImplStrFirstPartCharsetDef;
132 /* ======================================================================= */
134 sal_Bool SAL_CALL rtl_getTextEncodingInfo( rtl_TextEncoding eTextEncoding, rtl_TextEncodingInfo* pEncInfo )
136 const ImplTextEncodingData* pData;
138 pData = Impl_getTextEncodingData( eTextEncoding );
139 if ( !pData )
141 /* HACK: For not implemented encoding, because not all
142 calls handle the errors */
143 if ( pEncInfo->StructSize < 5 )
144 return sal_False;
145 pEncInfo->MinimumCharSize = 1;
147 if ( pEncInfo->StructSize < 6 )
148 return sal_True;
149 pEncInfo->MaximumCharSize = 1;
151 if ( pEncInfo->StructSize < 7 )
152 return sal_True;
153 pEncInfo->AverageCharSize = 1;
155 if ( pEncInfo->StructSize < 12 )
156 return sal_True;
157 pEncInfo->Flags = 0;
159 return sal_False;
162 if ( pEncInfo->StructSize < 5 )
163 return sal_False;
164 pEncInfo->MinimumCharSize = pData->mnMinCharSize;
166 if ( pEncInfo->StructSize < 6 )
167 return sal_True;
168 pEncInfo->MaximumCharSize = pData->mnMaxCharSize;
170 if ( pEncInfo->StructSize < 7 )
171 return sal_True;
172 pEncInfo->AverageCharSize = pData->mnAveCharSize;
174 if ( pEncInfo->StructSize < 12 )
175 return sal_True;
176 pEncInfo->Flags = pData->mnInfoFlags;
178 return sal_True;
181 /* ======================================================================= */
183 rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromWindowsCharset( sal_uInt8 nWinCharset )
185 rtl_TextEncoding eTextEncoding;
187 switch ( nWinCharset )
189 case 0: eTextEncoding = RTL_TEXTENCODING_MS_1252; break; /* ANSI_CHARSET */
190 case 2: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break; /* SYMBOL_CHARSET */
191 case 77: eTextEncoding = RTL_TEXTENCODING_APPLE_ROMAN; break;/* MAC_CHARSET */
192 case 128: eTextEncoding = RTL_TEXTENCODING_MS_932; break; /* SHIFTJIS_CHARSET */
193 case 129: eTextEncoding = RTL_TEXTENCODING_MS_949; break; /* HANGEUL_CHARSET */
194 case 130: eTextEncoding = RTL_TEXTENCODING_MS_1361; break; /* JOHAB_CHARSET */
195 case 134: eTextEncoding = RTL_TEXTENCODING_MS_936; break; /* GB2312_CHARSET */
196 case 136: eTextEncoding = RTL_TEXTENCODING_MS_950; break; /* CHINESEBIG5_CHARSET */
197 case 161: eTextEncoding = RTL_TEXTENCODING_MS_1253; break; /* GREEK_CHARSET */
198 case 162: eTextEncoding = RTL_TEXTENCODING_MS_1254; break; /* TURKISH_CHARSET */
199 case 163: eTextEncoding = RTL_TEXTENCODING_MS_1258; break; /* VIETNAMESE_CHARSET !!! */
200 case 177: eTextEncoding = RTL_TEXTENCODING_MS_1255; break; /* HEBREW_CHARSET */
201 case 178: eTextEncoding = RTL_TEXTENCODING_MS_1256; break; /* ARABIC_CHARSET */
202 case 186: eTextEncoding = RTL_TEXTENCODING_MS_1257; break; /* BALTIC_CHARSET */
203 case 204: eTextEncoding = RTL_TEXTENCODING_MS_1251; break; /* RUSSIAN_CHARSET */
204 case 222: eTextEncoding = RTL_TEXTENCODING_MS_874; break; /* THAI_CHARSET */
205 case 238: eTextEncoding = RTL_TEXTENCODING_MS_1250; break; /* EASTEUROPE_CHARSET */
206 case 255: eTextEncoding = RTL_TEXTENCODING_IBM_850; break; /* OEM_CHARSET */
207 default: eTextEncoding = RTL_TEXTENCODING_DONTKNOW; break;
210 return eTextEncoding;
213 /* ----------------------------------------------------------------------- */
215 #if 0
217 rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromMacTextEncoding( sal_uInt32 nMacTextEncoding )
219 rtl_TextEncoding eTextEncoding;
221 switch ( nMacTextEncoding )
223 case 0: eTextEncoding = RTL_TEXTENCODING_APPLE_ROMAN; break;
224 case 1: eTextEncoding = RTL_TEXTENCODING_APPLE_JAPANESE; break;
225 case 2: eTextEncoding = RTL_TEXTENCODING_APPLE_CHINTRAD; break;
226 case 3: eTextEncoding = RTL_TEXTENCODING_APPLE_KOREAN; break;
227 case 4: eTextEncoding = RTL_TEXTENCODING_APPLE_ARABIC; break;
228 case 5: eTextEncoding = RTL_TEXTENCODING_APPLE_HEBREW; break;
229 case 6: eTextEncoding = RTL_TEXTENCODING_APPLE_GREEK; break;
230 case 7: eTextEncoding = RTL_TEXTENCODING_APPLE_CYRILLIC; break;
231 /* RIGHT-TO-LEFT SYMBOLS = 8 ??? */
232 case 9: eTextEncoding = RTL_TEXTENCODING_APPLE_DEVANAGARI; break;
233 case 10: eTextEncoding = RTL_TEXTENCODING_APPLE_GURMUKHI; break;
234 case 11: eTextEncoding = RTL_TEXTENCODING_APPLE_GUJARATI; break;
235 /* MacOriya = 12 */
236 /* MacBengali = 13 */
237 /* MacTamil = 14 */
238 /* MacTelugu = 15 */
239 /* MacKannada = 16 */
240 /* MacMalayalam = 17 */
241 /* MacSinhalese = 18 */
242 /* MacBurmese = 19 */
243 /* MacKhmer = 20 */
244 case 21: eTextEncoding = RTL_TEXTENCODING_APPLE_THAI; break;
245 /* MacLaotian = 22 */
246 /* MacGeorgian = 23 */
247 /* MacArmenian = 24 */
248 case 25: eTextEncoding = RTL_TEXTENCODING_APPLE_CHINSIMP; break;
249 /* MacTibetan = 26 */
250 /* MacMongolian = 27 */
251 /* MacEthiopic = 28 */
252 case 29: eTextEncoding = RTL_TEXTENCODING_APPLE_CENTEURO; break; /* MacCentralEurRoman */
253 /* MacVietnamese = 30 */
254 /* MacExtArabic = 31 */
255 case 32: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break;
256 case 33: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break; /* MacSymbol */
257 case 34: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break; /* MacDingbats */
258 case 35: eTextEncoding = RTL_TEXTENCODING_APPLE_TURKISH; break; /* MacTurkish */
259 case 36: eTextEncoding = RTL_TEXTENCODING_APPLE_CROATIAN; break; /* MacCroatian */
260 case 37: eTextEncoding = RTL_TEXTENCODING_APPLE_ICELAND; break; /* MacIcelandic */
261 case 38: eTextEncoding = RTL_TEXTENCODING_APPLE_ROMANIAN; break; /* MacRomanian */
262 /* MacCeltic = 39 */
263 /* MacGaelic = 40 */
264 /* Beginning in Mac OS 8.5, the set of Mac OS script codes has been */
265 /* extended for some Mac OS components to include Unicode. Some of */
266 /* these components have only 7 bits available for script code, so */
267 /* kTextEncodingUnicodeDefault cannot be used to indicate Unicode. */
268 /* Instead, the following meta-value is used to indicate Unicode */
269 /* handled as a special Mac OS script code; TEC handles this value */
270 /* like kTextEncodingUnicodeDefault. */
271 /* The following use script code 4, smArabic */
272 case 0x08C: eTextEncoding = RTL_TEXTENCODING_APPLE_FARSI; break; /* MacFarsi */
273 /* The following use script code 7, smCyrillic */
274 case 0x098: eTextEncoding = RTL_TEXTENCODING_APPLE_UKRAINIAN; break; /* MacUkrainian */
275 /* The following use script code 28, smEthiopic */
276 /* MacInuit = 0xEC */
277 /* The following use script code 32, smUninterp */
278 case 0x0FC: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break; /* MacVT100 - VT100/102 font */
279 /* Special Mac OS encodings */
280 /* MacHFS = 0xFF */ /* metavalue. */
281 /* Unicode & ISO UCS encodings begin at 0x100 */
282 case 0x100: eTextEncoding = RTL_TEXTENCODING_UNICODE; break; /* UnicodeDefault */
283 case 0x101: eTextEncoding = RTL_TEXTENCODING_UNICODE; break; /* UnicodeV1_1 / ISO10646_1993 */
284 case 0x103: eTextEncoding = RTL_TEXTENCODING_UNICODE; break; /* UnicodeV2_1 - new location for Korean Hangul / UnicodeV2_1 */
285 /* ISO 8-bit and 7-bit encodings begin at 0x200 */
286 case 0x201: eTextEncoding = RTL_TEXTENCODING_ISO_8859_1; break; /* ISOLatin1 - ISO 8859-1 */
287 case 0x202: eTextEncoding = RTL_TEXTENCODING_ISO_8859_2; break; /* ISOLatin2 - ISO 8859-2 */
288 case 0x203: eTextEncoding = RTL_TEXTENCODING_ISO_8859_3; break; /* ISOLatin3 - ISO 8859-3 */
289 case 0x204: eTextEncoding = RTL_TEXTENCODING_ISO_8859_4; break; /* ISOLatin4 - ISO 8859-4 */
290 case 0x205: eTextEncoding = RTL_TEXTENCODING_ISO_8859_5; break; /* ISOLatinCyrillic - ISO 8859-5 */
291 case 0x206: eTextEncoding = RTL_TEXTENCODING_ISO_8859_6; break; /* ISOLatinArabic - ISO 8859-6, = ASMO 708, =DOS CP 708 */
292 case 0x207: eTextEncoding = RTL_TEXTENCODING_ISO_8859_7; break; /* ISOLatinGreek - ISO 8859-7 */
293 case 0x208: eTextEncoding = RTL_TEXTENCODING_ISO_8859_8; break; /* ISOLatinHebrew - ISO 8859-8 */
294 case 0x209: eTextEncoding = RTL_TEXTENCODING_ISO_8859_9; break; /* ISOLatin5 - ISO 8859-9 */
295 /* MS-DOS & Windows encodings begin at 0x400 */
296 case 0x400: eTextEncoding = RTL_TEXTENCODING_IBM_437; break; /* DOSLatinUS - code page 437 */
297 case 0x405: eTextEncoding = RTL_TEXTENCODING_IBM_737; break; /* DOSGreek - code page 737 (formerly 437G) */
298 case 0x406: eTextEncoding = RTL_TEXTENCODING_IBM_775; break; /* DOSBalticRim - code page 775 */
299 case 0x410: eTextEncoding = RTL_TEXTENCODING_IBM_850; break; /* DOSLatin1 - code page 850, "Multilingual" */
300 /* !!! case 0x411: eTextEncoding = RTL_TEXTENCODING_IBM_851; break; */ /* DOSGreek1 - code page 851 */
301 case 0x412: eTextEncoding = RTL_TEXTENCODING_IBM_852; break; /* DOSLatin2 - code page 852, Slavic */
302 case 0x413: eTextEncoding = RTL_TEXTENCODING_IBM_855; break; /* DOSCyrillic - code page 855, IBM Cyrillic */
303 case 0x414: eTextEncoding = RTL_TEXTENCODING_IBM_857; break; /* DOSTurkish - code page 857, IBM Turkish */
304 case 0x415: eTextEncoding = RTL_TEXTENCODING_IBM_860; break; /* DOSPortuguese - code page 860 */
305 case 0x416: eTextEncoding = RTL_TEXTENCODING_IBM_861; break; /* DOSIcelandic - code page 861 */
306 case 0x417: eTextEncoding = RTL_TEXTENCODING_IBM_862; break; /* DOSHebrew - code page 862 */
307 case 0x418: eTextEncoding = RTL_TEXTENCODING_IBM_863; break; /* DOSCanadianFrench - code page 863 */
308 case 0x419: eTextEncoding = RTL_TEXTENCODING_IBM_864; break; /* DOSArabic - code page 864 */
309 case 0x41A: eTextEncoding = RTL_TEXTENCODING_IBM_865; break; /* DOSNordic - code page 865 */
310 case 0x41B: eTextEncoding = RTL_TEXTENCODING_IBM_866; break; /* DOSRussian - code page 866 */
311 case 0x41C: eTextEncoding = RTL_TEXTENCODING_IBM_869; break; /* DOSGreek2 - code page 869, IBM Modern Greek */
312 case 0x41D: eTextEncoding = RTL_TEXTENCODING_MS_874; break; /* DOSThai - code page 874, also for Windows */
313 case 0x420: eTextEncoding = RTL_TEXTENCODING_MS_932; break; /* DOSJapanese - code page 932, also for Windows */
314 case 0x421: eTextEncoding = RTL_TEXTENCODING_MS_936; break; /* DOSChineseSimplif - code page 936, also for Windows */
315 case 0x422: eTextEncoding = RTL_TEXTENCODING_MS_949; break; /* DOSKorean - code page 949, also for Windows;Unified Hangul */
316 case 0x423: eTextEncoding = RTL_TEXTENCODING_MS_950; break; /* DOSChineseTrad - code page 950, also for Windows */
317 case 0x500: eTextEncoding = RTL_TEXTENCODING_MS_1252; break; /* WindowsLatin1 / WindowsANSI - code page 1252 */
318 case 0x501: eTextEncoding = RTL_TEXTENCODING_MS_1250; break; /* WindowsLatin2 - code page 1250, Central Europe */
319 case 0x502: eTextEncoding = RTL_TEXTENCODING_MS_1251; break; /* WindowsCyrillic - code page 1251, Slavic Cyrillic */
320 case 0x503: eTextEncoding = RTL_TEXTENCODING_MS_1253; break; /* WindowsGreek - code page 1253 */
321 case 0x504: eTextEncoding = RTL_TEXTENCODING_MS_1254; break; /* WindowsLatin5 - code page 1254, Turkish */
322 case 0x505: eTextEncoding = RTL_TEXTENCODING_MS_1255; break; /* WindowsHebrew - code page 1255 */
323 case 0x506: eTextEncoding = RTL_TEXTENCODING_MS_1256; break; /* WindowsArabic - code page 1256 */
324 case 0x507: eTextEncoding = RTL_TEXTENCODING_MS_1257; break; /* WindowsBalticRim - code page 1257 */
325 case 0x508: eTextEncoding = RTL_TEXTENCODING_MS_1258; break; /* WindowsVietnamese - code page 1258 */
326 case 0x510: eTextEncoding = RTL_TEXTENCODING_MS_1361; break; /* WindowsKoreanJohab - code page 1361, for Windows NT */
327 /* Various national standards begin at 0x600 */
328 case 0x600: eTextEncoding = RTL_TEXTENCODING_ASCII_US; break; /* US_ASCII */
329 case 0x620: eTextEncoding = RTL_TEXTENCODING_JIS_X_0201; break; /* JIS_X0201_76 */
330 case 0x621: eTextEncoding = RTL_TEXTENCODING_JIS_X_0208; break; /* JIS_X0208_83 */
331 case 0x622: eTextEncoding = RTL_TEXTENCODING_JIS_X_0208; break; /* JIS_X0208_90 */
332 case 0x623: eTextEncoding = RTL_TEXTENCODING_JIS_X_0212; break; /* JIS_X0212_90 */
333 /* !!! JIS_C6226_78 = 0x624 */
334 /* !!! GB_2312_80 = 0x630 */
335 /* !!! GBK_95 = 0x631 */ /* annex to GB 13000-93; for Windows 95 */
336 // case 0x640: eTextEncoding = RTL_TEXTENCODING_KSC_5601_1987; break; /* KSC_5601_87 */ /* same as KSC 5601-92 without Johab annex */
337 // case 0x641: eTextEncoding = RTL_TEXTENCODING_KSC_5601_1992; break; /* KSC 5601-92 Johab annex */
338 /* !!! CNS_11643_92_P1 = 0x651 */ /* CNS 11643-1992 plane 1 */
339 /* !!! CNS_11643_92_P2 = 0x652 */ /* CNS 11643-1992 plane 2 */
340 /* !!! CNS_11643_92_P3 = 0x653 */ /* CNS 11643-1992 plane 3 (11643-1986 plane 14) */
341 /* ISO 2022 collections begin at 0x800 */
342 case 0x820: eTextEncoding = RTL_TEXTENCODING_ISO_2022_JP; break; /* ISO_2022_JP */
343 case 0x821: eTextEncoding = RTL_TEXTENCODING_ISO_2022_JP; break; /* ISO_2022_JP_2 */
344 case 0x830: eTextEncoding = RTL_TEXTENCODING_ISO_2022_CN; break; /* ISO_2022_CN */
345 case 0x831: eTextEncoding = RTL_TEXTENCODING_ISO_2022_CN; break; /* ISO_2022_CN_EXT */
346 /* !!! ISO_2022_KR = 0x840 */
347 /* EUC collections begin at 0x900 */
348 case 0x920: eTextEncoding = RTL_TEXTENCODING_EUC_JP; break; /* EUC_JP - ISO 646,1-byte Katakana,JIS 208,JIS 212 */
349 case 0x930: eTextEncoding = RTL_TEXTENCODING_EUC_CN; break; /* EUC_CN - ISO 646, GB 2312-80 */
350 case 0x931: eTextEncoding = RTL_TEXTENCODING_EUC_TW; break; /* EUC_TW - ISO 646, CNS 11643-1992 Planes 1-16 */
351 case 0x940: eTextEncoding = RTL_TEXTENCODING_EUC_KR; break; /* EUC_KR - ISO 646, KS C 5601-1987 */
352 /* Miscellaneous standards begin at 0xA00 */
353 case 0xA01: eTextEncoding = RTL_TEXTENCODING_SHIFT_JIS; break; /* ShiftJIS - plain Shift-JIS */
354 case 0xA02: eTextEncoding = RTL_TEXTENCODING_KOI8_R; break; /* KOI8_R - Russian Internet standard */
355 case 0xA03: eTextEncoding = RTL_TEXTENCODING_BIG5; break; /* Big5 - Big-5 */
356 /* !!! MacRomanLatin1 = 0xA04 */ /* Mac OS Roman permuted to align with 8859-1 */
357 /* !!! HZ_GB_2312 = 0xA05 */ /* HZ (RFC 1842, for Chinese mail & news) */
358 /* Other platform encodings */
359 /* !!! NextStepLatin = 0xB01 */ /* NextStep encoding */
360 /* EBCDIC & IBM host encodings begin at 0xC00 */
361 /* !!! EBCDIC_US = 0xC01 */ /* basic EBCDIC-US */
362 /* !!! EBCDIC_CP037 = 0xC02 */ /* code page 037, extended EBCDIC-US Latin1 */
363 /* Special value */
364 /* MultiRun = 0xFFF */ /* Multiple encoded text, external run info */
365 default: eTextEncoding = RTL_TEXTENCODING_DONTKNOW; break;
368 return eTextEncoding;
371 #endif
373 /* ----------------------------------------------------------------------- */
375 rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromUnixCharset( const sal_Char* pUnixCharset )
377 /* See <ftp://ftp.x.org/pub/DOCS/registry>, section 14 ("Font Charset
378 * (Registry and Encoding) Names").
381 /* All Identifiers in the tables are lower case The function search */
382 /* for the first matching string in the tables. */
383 /* Sort order: unique (first 14, than 1), important */
385 static ImplStrCharsetDef const aUnixCharsetISOTab[] =
387 { "15", RTL_TEXTENCODING_ISO_8859_15 },
388 { "14", RTL_TEXTENCODING_ISO_8859_14 },
389 { "13", RTL_TEXTENCODING_ISO_8859_13 },
390 { "11", RTL_TEXTENCODING_TIS_620 },
391 { "10", RTL_TEXTENCODING_ISO_8859_10 },
392 { "1", RTL_TEXTENCODING_ISO_8859_1 },
393 { "2", RTL_TEXTENCODING_ISO_8859_2 },
394 { "3", RTL_TEXTENCODING_ISO_8859_3 },
395 { "4", RTL_TEXTENCODING_ISO_8859_4 },
396 { "5", RTL_TEXTENCODING_ISO_8859_5 },
397 { "6", RTL_TEXTENCODING_ISO_8859_6 },
398 { "7", RTL_TEXTENCODING_ISO_8859_7 },
399 { "8", RTL_TEXTENCODING_ISO_8859_8 },
400 { "9", RTL_TEXTENCODING_ISO_8859_9 },
401 { NULL, RTL_TEXTENCODING_DONTKNOW }
404 static ImplStrCharsetDef const aUnixCharsetADOBETab[] =
406 { "fontspecific", RTL_TEXTENCODING_SYMBOL },
407 { NULL, RTL_TEXTENCODING_DONTKNOW }
410 static ImplStrCharsetDef const aUnixCharsetMSTab[] =
412 { "1252", RTL_TEXTENCODING_MS_1252 },
413 { "1250", RTL_TEXTENCODING_MS_1250 },
414 { "1251", RTL_TEXTENCODING_MS_1251 },
415 { "1253", RTL_TEXTENCODING_MS_1253 },
416 { "1254", RTL_TEXTENCODING_MS_1254 },
417 { "1255", RTL_TEXTENCODING_MS_1255 },
418 { "1256", RTL_TEXTENCODING_MS_1256 },
419 { "1257", RTL_TEXTENCODING_MS_1257 },
420 { "1258", RTL_TEXTENCODING_MS_1258 },
421 { "932", RTL_TEXTENCODING_MS_932 },
422 { "936", RTL_TEXTENCODING_MS_936 },
423 { "949", RTL_TEXTENCODING_MS_949 },
424 { "950", RTL_TEXTENCODING_MS_950 },
425 { "1361", RTL_TEXTENCODING_MS_1361 },
426 { "cp1252", RTL_TEXTENCODING_MS_1252 },
427 { "cp1250", RTL_TEXTENCODING_MS_1250 },
428 { "cp1251", RTL_TEXTENCODING_MS_1251 },
429 { "cp1253", RTL_TEXTENCODING_MS_1253 },
430 { "cp1254", RTL_TEXTENCODING_MS_1254 },
431 { "cp1255", RTL_TEXTENCODING_MS_1255 },
432 { "cp1256", RTL_TEXTENCODING_MS_1256 },
433 { "cp1257", RTL_TEXTENCODING_MS_1257 },
434 { "cp1258", RTL_TEXTENCODING_MS_1258 },
435 { "cp932", RTL_TEXTENCODING_MS_932 },
436 { "cp936", RTL_TEXTENCODING_MS_936 },
437 { "cp949", RTL_TEXTENCODING_MS_949 },
438 { "cp950", RTL_TEXTENCODING_MS_950 },
439 { "cp1361", RTL_TEXTENCODING_MS_1361 },
440 { NULL, RTL_TEXTENCODING_DONTKNOW }
443 static ImplStrCharsetDef const aUnixCharsetIBMTab[] =
445 { "437", RTL_TEXTENCODING_IBM_437 },
446 { "850", RTL_TEXTENCODING_IBM_850 },
447 { "860", RTL_TEXTENCODING_IBM_860 },
448 { "861", RTL_TEXTENCODING_IBM_861 },
449 { "863", RTL_TEXTENCODING_IBM_863 },
450 { "865", RTL_TEXTENCODING_IBM_865 },
451 { "737", RTL_TEXTENCODING_IBM_737 },
452 { "775", RTL_TEXTENCODING_IBM_775 },
453 { "852", RTL_TEXTENCODING_IBM_852 },
454 { "855", RTL_TEXTENCODING_IBM_855 },
455 { "857", RTL_TEXTENCODING_IBM_857 },
456 { "862", RTL_TEXTENCODING_IBM_862 },
457 { "864", RTL_TEXTENCODING_IBM_864 },
458 { "866", RTL_TEXTENCODING_IBM_866 },
459 { "869", RTL_TEXTENCODING_IBM_869 },
460 { "874", RTL_TEXTENCODING_MS_874 },
461 { "1004", RTL_TEXTENCODING_MS_1252 },
462 { "65400", RTL_TEXTENCODING_SYMBOL },
463 { NULL, RTL_TEXTENCODING_DONTKNOW }
466 static ImplStrCharsetDef const aUnixCharsetKOI8Tab[] =
468 { "r", RTL_TEXTENCODING_KOI8_R },
469 { "u", RTL_TEXTENCODING_KOI8_U },
470 { NULL, RTL_TEXTENCODING_DONTKNOW }
473 static ImplStrCharsetDef aUnixCharsetJISX0208Tab[] =
475 { NULL, RTL_TEXTENCODING_JIS_X_0208 }
478 static ImplStrCharsetDef aUnixCharsetJISX0201Tab[] =
480 { NULL, RTL_TEXTENCODING_JIS_X_0201 }
483 static ImplStrCharsetDef aUnixCharsetJISX0212Tab[] =
485 { NULL, RTL_TEXTENCODING_JIS_X_0212 }
488 static ImplStrCharsetDef aUnixCharsetGBTab[] =
490 { NULL, RTL_TEXTENCODING_GB_2312 }
493 static ImplStrCharsetDef aUnixCharsetGBKTab[] =
495 { NULL, RTL_TEXTENCODING_GBK }
498 static ImplStrCharsetDef aUnixCharsetBIG5Tab[] =
500 { NULL, RTL_TEXTENCODING_BIG5 }
503 static ImplStrCharsetDef const aUnixCharsetKSC56011987Tab[] =
505 { NULL, RTL_TEXTENCODING_EUC_KR }
508 static ImplStrCharsetDef const aUnixCharsetKSC56011992Tab[] =
510 { NULL, RTL_TEXTENCODING_MS_1361 }
513 static ImplStrCharsetDef const aUnixCharsetISO10646Tab[] =
515 { NULL, RTL_TEXTENCODING_UNICODE }
518 static ImplStrCharsetDef const aUnixCharsetUNICODETab[] =
520 /* Currently every Unicode Encoding is for us Unicode */
521 /* { "fontspecific", RTL_TEXTENCODING_UNICODE }, */
522 { NULL, RTL_TEXTENCODING_UNICODE }
525 static ImplStrCharsetDef const aUnixCharsetSymbolTab[] =
527 { NULL, RTL_TEXTENCODING_SYMBOL }
530 /* See <http://cvs.freedesktop.org/xorg/xc/fonts/encodings/iso8859-11.enc?
531 rev=1.1.1.1>: */
532 static ImplStrCharsetDef const aUnixCharsetTIS620Tab[] =
534 { "0", RTL_TEXTENCODING_TIS_620 },
535 { "2529", RTL_TEXTENCODING_TIS_620 },
536 { "2533", RTL_TEXTENCODING_TIS_620 },
537 { NULL, RTL_TEXTENCODING_DONTKNOW }
539 static ImplStrCharsetDef const aUnixCharsetTIS6202529Tab[] =
541 { "1", RTL_TEXTENCODING_TIS_620 },
542 { NULL, RTL_TEXTENCODING_DONTKNOW }
544 static ImplStrCharsetDef const aUnixCharsetTIS6202533Tab[] =
546 { "0", RTL_TEXTENCODING_TIS_620 },
547 { "1", RTL_TEXTENCODING_TIS_620 },
548 { NULL, RTL_TEXTENCODING_DONTKNOW }
551 static ImplStrFirstPartCharsetDef const aUnixCharsetFirstPartTab[] =
553 { "iso8859", aUnixCharsetISOTab },
554 { "adobe", aUnixCharsetADOBETab },
555 { "ansi", aUnixCharsetMSTab },
556 { "microsoft", aUnixCharsetMSTab },
557 { "ibm", aUnixCharsetIBMTab },
558 { "koi8", aUnixCharsetKOI8Tab },
559 { "jisx0208", aUnixCharsetJISX0208Tab },
560 { "jisx0208.1983", aUnixCharsetJISX0208Tab },
561 { "jisx0201", aUnixCharsetJISX0201Tab },
562 { "jisx0201.1976", aUnixCharsetJISX0201Tab },
563 { "jisx0212", aUnixCharsetJISX0212Tab },
564 { "jisx0212.1990", aUnixCharsetJISX0212Tab },
565 { "gb2312", aUnixCharsetGBTab },
566 { "gbk", aUnixCharsetGBKTab },
567 { "big5", aUnixCharsetBIG5Tab },
568 { "iso10646", aUnixCharsetISO10646Tab },
569 /* { "unicode", aUnixCharsetUNICODETab }, */ /* fonts contain only default chars */
570 { "sunolcursor", aUnixCharsetSymbolTab },
571 { "sunolglyph", aUnixCharsetSymbolTab },
572 { "iso10646", aUnixCharsetUNICODETab },
573 { "ksc5601.1987", aUnixCharsetKSC56011987Tab },
574 { "ksc5601.1992", aUnixCharsetKSC56011992Tab },
575 { "tis620.2529", aUnixCharsetTIS6202529Tab },
576 { "tis620.2533", aUnixCharsetTIS6202533Tab },
577 { "tis620", aUnixCharsetTIS620Tab },
578 /* { "sunudcja.1997", }, */
579 /* { "sunudcko.1997", }, */
580 /* { "sunudczh.1997", }, */
581 /* { "sunudczhtw.1997", }, */
582 { NULL, NULL }
585 rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
586 sal_Char* pBuf;
587 sal_Char* pTempBuf;
588 sal_uInt32 nBufLen = strlen( pUnixCharset )+1;
589 const sal_Char* pFirstPart;
590 const sal_Char* pSecondPart;
592 /* Alloc Buffer and map to lower case */
593 pBuf = (char*)rtl_allocateMemory( nBufLen );
594 Impl_toAsciiLower( pUnixCharset, pBuf );
596 /* Search FirstPart */
597 pFirstPart = pBuf;
598 pSecondPart = NULL;
599 pTempBuf = pBuf;
600 while ( *pTempBuf )
602 if ( *pTempBuf == '-' )
604 *pTempBuf = '\0';
605 pSecondPart = pTempBuf+1;
606 break;
609 pTempBuf++;
612 /* Parttrenner gefunden */
613 if ( pSecondPart )
615 /* Search for the part tab */
616 const ImplStrFirstPartCharsetDef* pFirstPartData = aUnixCharsetFirstPartTab;
617 while ( pFirstPartData->mpCharsetStr )
619 if ( Impl_matchString( pFirstPart, pFirstPartData->mpCharsetStr ) )
621 /* Search for the charset in the second part tab */
622 const ImplStrCharsetDef* pData = pFirstPartData->mpSecondPartTab;
623 while ( pData->mpCharsetStr )
625 if ( Impl_matchString( pSecondPart, pData->mpCharsetStr ) )
627 eEncoding = pData->meTextEncoding;
628 break;
631 pData++;
634 /* use default encoding for first part */
635 eEncoding = pData->meTextEncoding;
636 break;
639 pFirstPartData++;
643 rtl_freeMemory( pBuf );
645 return eEncoding;
648 /* ----------------------------------------------------------------------- */
650 rtl_TextEncoding SAL_CALL rtl_getTextEncodingFromMimeCharset( const sal_Char* pMimeCharset )
652 /* All Identifiers are in lower case and contain only alphanumeric */
653 /* characters. The function search for the first equal string in */
654 /* the table. In this table are only the most used mime types. */
655 /* Sort order: important */
656 static ImplStrCharsetDef const aVIPMimeCharsetTab[] =
658 { "usascii", RTL_TEXTENCODING_ASCII_US },
659 { "utf8", RTL_TEXTENCODING_UTF8 },
660 { "utf7", RTL_TEXTENCODING_UTF7 },
661 { "iso88591", RTL_TEXTENCODING_ISO_8859_1 },
662 { "iso88592", RTL_TEXTENCODING_ISO_8859_2 },
663 { "iso88593", RTL_TEXTENCODING_ISO_8859_3 },
664 { "iso88594", RTL_TEXTENCODING_ISO_8859_4 },
665 { "iso88595", RTL_TEXTENCODING_ISO_8859_5 },
666 { "iso88596", RTL_TEXTENCODING_ISO_8859_6 },
667 { "iso88597", RTL_TEXTENCODING_ISO_8859_7 },
668 { "iso88598", RTL_TEXTENCODING_ISO_8859_8 },
669 { "iso88599", RTL_TEXTENCODING_ISO_8859_9 },
670 { "iso885910", RTL_TEXTENCODING_ISO_8859_10 },
671 { "iso885913", RTL_TEXTENCODING_ISO_8859_13 },
672 { "iso885914", RTL_TEXTENCODING_ISO_8859_14 },
673 { "iso885915", RTL_TEXTENCODING_ISO_8859_15 },
674 { "iso2022jp", RTL_TEXTENCODING_ISO_2022_JP },
675 { "iso2022jp2", RTL_TEXTENCODING_ISO_2022_JP },
676 { "iso2022cn", RTL_TEXTENCODING_ISO_2022_CN },
677 { "iso2022cnext", RTL_TEXTENCODING_ISO_2022_CN },
678 { "iso2022kr", RTL_TEXTENCODING_ISO_2022_KR },
679 { "eucjp", RTL_TEXTENCODING_EUC_JP },
680 { "shiftjis", RTL_TEXTENCODING_SHIFT_JIS },
681 { "mskanji", RTL_TEXTENCODING_MS_932 },
682 { "gb2312", RTL_TEXTENCODING_GB_2312 },
683 { "cngb", RTL_TEXTENCODING_GB_2312 },
684 { "big5", RTL_TEXTENCODING_BIG5 },
685 { "cnbig5", RTL_TEXTENCODING_BIG5 },
686 { "cngb12345", RTL_TEXTENCODING_GBT_12345 },
687 { "euckr", RTL_TEXTENCODING_EUC_KR },
688 { "koi8r", RTL_TEXTENCODING_KOI8_R },
689 { "windows1252", RTL_TEXTENCODING_MS_1252 },
690 { "windows1250", RTL_TEXTENCODING_MS_1250 },
691 { "windows1251", RTL_TEXTENCODING_MS_1251 },
692 { "windows1253", RTL_TEXTENCODING_MS_1253 },
693 { "windows1254", RTL_TEXTENCODING_MS_1254 },
694 { "windows1255", RTL_TEXTENCODING_MS_1255 },
695 { "windows1256", RTL_TEXTENCODING_MS_1256 },
696 { "windows1257", RTL_TEXTENCODING_MS_1257 },
697 { "windows1258", RTL_TEXTENCODING_MS_1258 },
698 { NULL, RTL_TEXTENCODING_DONTKNOW }
701 /* All Identifiers are in lower case and contain only alphanumeric */
702 /* characters. The function search for the first matching string in */
703 /* the table. */
704 /* Sort order: unique (first iso885914, than iso88591), important */
705 static ImplStrCharsetDef const aMimeCharsetTab[] =
707 { "unicode11utf7", RTL_TEXTENCODING_UTF7 },
708 { "caunicode11utf7", RTL_TEXTENCODING_UTF7 },
709 { "iso88591windows30", RTL_TEXTENCODING_ISO_8859_1 },
710 { "iso88591win", RTL_TEXTENCODING_MS_1252 },
711 { "iso88592win", RTL_TEXTENCODING_MS_1250 },
712 { "iso88599win", RTL_TEXTENCODING_MS_1254 },
713 { "iso885915", RTL_TEXTENCODING_ISO_8859_15 },
714 { "iso885914", RTL_TEXTENCODING_ISO_8859_14 },
715 { "iso885913", RTL_TEXTENCODING_ISO_8859_13 },
716 { "iso885911", RTL_TEXTENCODING_TIS_620 },
717 /* This is no official MIME character set name, but it might be in
718 use in Thailand. */
719 { "iso885910", RTL_TEXTENCODING_ISO_8859_10 },
720 { "iso88591", RTL_TEXTENCODING_ISO_8859_1 },
721 { "iso88592", RTL_TEXTENCODING_ISO_8859_2 },
722 { "iso88593", RTL_TEXTENCODING_ISO_8859_3 },
723 { "iso88594", RTL_TEXTENCODING_ISO_8859_4 },
724 { "iso88595", RTL_TEXTENCODING_ISO_8859_5 },
725 { "iso88596", RTL_TEXTENCODING_ISO_8859_6 },
726 { "iso88597", RTL_TEXTENCODING_ISO_8859_7 },
727 { "iso88598", RTL_TEXTENCODING_ISO_8859_8 },
728 { "iso88599", RTL_TEXTENCODING_ISO_8859_9 },
729 { "isoir100", RTL_TEXTENCODING_ISO_8859_1 },
730 { "latin1", RTL_TEXTENCODING_ISO_8859_1 },
731 { "l1", RTL_TEXTENCODING_ISO_8859_1 },
732 { "cp819", RTL_TEXTENCODING_ISO_8859_1 },
733 { "ibm819", RTL_TEXTENCODING_ISO_8859_1 },
734 { "csisolatin1", RTL_TEXTENCODING_ISO_8859_1 },
735 { "isoir101", RTL_TEXTENCODING_ISO_8859_2 },
736 { "latin2", RTL_TEXTENCODING_ISO_8859_2 },
737 { "l2", RTL_TEXTENCODING_ISO_8859_2 },
738 { "csisolatin2", RTL_TEXTENCODING_ISO_8859_2 },
739 { "isoir109", RTL_TEXTENCODING_ISO_8859_3 },
740 { "latin3", RTL_TEXTENCODING_ISO_8859_3 },
741 { "l3", RTL_TEXTENCODING_ISO_8859_3 },
742 { "csisolatin3", RTL_TEXTENCODING_ISO_8859_3 },
743 { "isoir110", RTL_TEXTENCODING_ISO_8859_4 },
744 { "latin4", RTL_TEXTENCODING_ISO_8859_4 },
745 { "l4", RTL_TEXTENCODING_ISO_8859_4 },
746 { "csisolatin4", RTL_TEXTENCODING_ISO_8859_4 },
747 { "isoir144", RTL_TEXTENCODING_ISO_8859_5 },
748 { "cyrillicasian", RTL_TEXTENCODING_PT154 },
749 { "cyrillic", RTL_TEXTENCODING_ISO_8859_5 },
750 { "csisolatincyrillic", RTL_TEXTENCODING_ISO_8859_5 },
751 { "isoir127", RTL_TEXTENCODING_ISO_8859_6 },
752 { "arabic", RTL_TEXTENCODING_ISO_8859_6 },
753 { "csisolatinarabic", RTL_TEXTENCODING_ISO_8859_6 },
754 { "ecma114", RTL_TEXTENCODING_ISO_8859_6 },
755 { "asmo708", RTL_TEXTENCODING_ISO_8859_6 },
756 { "isoir126", RTL_TEXTENCODING_ISO_8859_7 },
757 { "greek", RTL_TEXTENCODING_ISO_8859_7 },
758 { "csisolatingreek", RTL_TEXTENCODING_ISO_8859_7 },
759 { "elot928", RTL_TEXTENCODING_ISO_8859_7 },
760 { "ecma118", RTL_TEXTENCODING_ISO_8859_7 },
761 { "isoir138", RTL_TEXTENCODING_ISO_8859_8 },
762 { "hebrew", RTL_TEXTENCODING_ISO_8859_8 },
763 { "csisolatinhebrew", RTL_TEXTENCODING_ISO_8859_8 },
764 { "isoir148", RTL_TEXTENCODING_ISO_8859_9 },
765 { "latin5", RTL_TEXTENCODING_ISO_8859_9 },
766 { "l5", RTL_TEXTENCODING_ISO_8859_9 },
767 { "csisolatin5", RTL_TEXTENCODING_ISO_8859_9 },
768 { "cswindows30latin1", RTL_TEXTENCODING_ISO_8859_1 },
769 { "cswindows30latin1", RTL_TEXTENCODING_ISO_8859_1 },
770 { "cswindows31latin1", RTL_TEXTENCODING_MS_1252 },
771 { "cswindows31latin2", RTL_TEXTENCODING_MS_1250 },
772 { "cswindows31latin5", RTL_TEXTENCODING_MS_1254 },
773 { "iso10646us", RTL_TEXTENCODING_ASCII_US },
774 { "iso646irv", RTL_TEXTENCODING_ASCII_US },
775 { "cskoi8r", RTL_TEXTENCODING_KOI8_R },
776 { "ibm437", RTL_TEXTENCODING_IBM_437 },
777 { "cp437", RTL_TEXTENCODING_IBM_437 },
778 { "437", RTL_TEXTENCODING_IBM_437 },
779 { "cspc8codepage437", RTL_TEXTENCODING_IBM_437 },
780 { "ansix34", RTL_TEXTENCODING_ASCII_US },
781 { "ibm367", RTL_TEXTENCODING_ASCII_US },
782 { "cp367", RTL_TEXTENCODING_ASCII_US },
783 { "csascii", RTL_TEXTENCODING_ASCII_US },
784 { "ibm775", RTL_TEXTENCODING_IBM_775 },
785 { "cp775", RTL_TEXTENCODING_IBM_775 },
786 { "cspc775baltic", RTL_TEXTENCODING_IBM_775 },
787 { "ibm850", RTL_TEXTENCODING_IBM_850 },
788 { "cp850", RTL_TEXTENCODING_IBM_850 },
789 { "850", RTL_TEXTENCODING_IBM_850 },
790 { "cspc850multilingual", RTL_TEXTENCODING_IBM_850 },
791 /* { "ibm851", RTL_TEXTENCODING_IBM_851 }, */
792 /* { "cp851", RTL_TEXTENCODING_IBM_851 }, */
793 /* { "851", RTL_TEXTENCODING_IBM_851 }, */
794 /* { "csibm851", RTL_TEXTENCODING_IBM_851 }, */
795 { "ibm852", RTL_TEXTENCODING_IBM_852 },
796 { "cp852", RTL_TEXTENCODING_IBM_852 },
797 { "852", RTL_TEXTENCODING_IBM_852 },
798 { "cspcp852", RTL_TEXTENCODING_IBM_852 },
799 { "ibm855", RTL_TEXTENCODING_IBM_855 },
800 { "cp855", RTL_TEXTENCODING_IBM_855 },
801 { "855", RTL_TEXTENCODING_IBM_855 },
802 { "csibm855", RTL_TEXTENCODING_IBM_855 },
803 { "ibm857", RTL_TEXTENCODING_IBM_857 },
804 { "cp857", RTL_TEXTENCODING_IBM_857 },
805 { "857", RTL_TEXTENCODING_IBM_857 },
806 { "csibm857", RTL_TEXTENCODING_IBM_857 },
807 { "ibm860", RTL_TEXTENCODING_IBM_860 },
808 { "cp860", RTL_TEXTENCODING_IBM_860 },
809 { "860", RTL_TEXTENCODING_IBM_860 },
810 { "csibm860", RTL_TEXTENCODING_IBM_860 },
811 { "ibm861", RTL_TEXTENCODING_IBM_861 },
812 { "cp861", RTL_TEXTENCODING_IBM_861 },
813 { "861", RTL_TEXTENCODING_IBM_861 },
814 { "csis", RTL_TEXTENCODING_IBM_861 },
815 { "csibm861", RTL_TEXTENCODING_IBM_861 },
816 { "ibm862", RTL_TEXTENCODING_IBM_862 },
817 { "cp862", RTL_TEXTENCODING_IBM_862 },
818 { "862", RTL_TEXTENCODING_IBM_862 },
819 { "cspc862latinhebrew", RTL_TEXTENCODING_IBM_862 },
820 { "ibm863", RTL_TEXTENCODING_IBM_863 },
821 { "cp863", RTL_TEXTENCODING_IBM_863 },
822 { "863", RTL_TEXTENCODING_IBM_863 },
823 { "csibm863", RTL_TEXTENCODING_IBM_863 },
824 { "ibm864", RTL_TEXTENCODING_IBM_864 },
825 { "cp864", RTL_TEXTENCODING_IBM_864 },
826 { "864", RTL_TEXTENCODING_IBM_864 },
827 { "csibm864", RTL_TEXTENCODING_IBM_864 },
828 { "ibm865", RTL_TEXTENCODING_IBM_865 },
829 { "cp865", RTL_TEXTENCODING_IBM_865 },
830 { "865", RTL_TEXTENCODING_IBM_865 },
831 { "csibm865", RTL_TEXTENCODING_IBM_865 },
832 { "ibm866", RTL_TEXTENCODING_IBM_866 },
833 { "cp866", RTL_TEXTENCODING_IBM_866 },
834 { "866", RTL_TEXTENCODING_IBM_866 },
835 { "csibm866", RTL_TEXTENCODING_IBM_866 },
836 /* { "ibm868", RTL_TEXTENCODING_IBM_868 }, */
837 /* { "cp868", RTL_TEXTENCODING_IBM_868 }, */
838 /* { "cpar", RTL_TEXTENCODING_IBM_868 }, */
839 /* { "csibm868", RTL_TEXTENCODING_IBM_868 }, */
840 { "ibm869", RTL_TEXTENCODING_IBM_869 },
841 { "cp869", RTL_TEXTENCODING_IBM_869 },
842 { "869", RTL_TEXTENCODING_IBM_869 },
843 { "cpgr", RTL_TEXTENCODING_IBM_869 },
844 { "csibm869", RTL_TEXTENCODING_IBM_869 },
845 { "ibm869", RTL_TEXTENCODING_IBM_869 },
846 { "cp869", RTL_TEXTENCODING_IBM_869 },
847 { "869", RTL_TEXTENCODING_IBM_869 },
848 { "cpgr", RTL_TEXTENCODING_IBM_869 },
849 { "csibm869", RTL_TEXTENCODING_IBM_869 },
850 { "mac", RTL_TEXTENCODING_APPLE_ROMAN },
851 { "csmacintosh", RTL_TEXTENCODING_APPLE_ROMAN },
852 { "shiftjis", RTL_TEXTENCODING_SHIFT_JIS },
853 { "mskanji", RTL_TEXTENCODING_MS_932 },
854 { "csshiftjis", RTL_TEXTENCODING_SHIFT_JIS },
855 { "jisx0208", RTL_TEXTENCODING_JIS_X_0208 },
856 { "jisc62261983", RTL_TEXTENCODING_JIS_X_0208 },
857 { "csiso87jisx0208", RTL_TEXTENCODING_JIS_X_0208 },
858 { "isoir86", RTL_TEXTENCODING_JIS_X_0208 },
859 { "x0208", RTL_TEXTENCODING_JIS_X_0208 },
860 { "jisx0201", RTL_TEXTENCODING_JIS_X_0201 },
861 { "cshalfwidthkatakana", RTL_TEXTENCODING_JIS_X_0201 },
862 { "x0201", RTL_TEXTENCODING_JIS_X_0201 },
863 { "jisx0212", RTL_TEXTENCODING_JIS_X_0212 },
864 { "csiso159jisx0212", RTL_TEXTENCODING_JIS_X_0212 },
865 { "isoir159", RTL_TEXTENCODING_JIS_X_0208 },
866 { "x0212", RTL_TEXTENCODING_JIS_X_0212 },
867 { "isoir6", RTL_TEXTENCODING_ASCII_US },
868 { "xsjis", RTL_TEXTENCODING_SHIFT_JIS },
869 { "sjis", RTL_TEXTENCODING_SHIFT_JIS },
870 { "ascii", RTL_TEXTENCODING_ASCII_US },
871 { "us", RTL_TEXTENCODING_ASCII_US },
872 { "gb180302000", RTL_TEXTENCODING_GB_18030 },
873 /* This is no actual MIME character set name, it is only in here
874 for backwards compatibility (before "GB18030" was officially
875 registered with IANA, this code contained some guesses of what
876 would become official names for GB18030). */
877 { "gb18030", RTL_TEXTENCODING_GB_18030 },
878 { "big5hkscs", RTL_TEXTENCODING_BIG5_HKSCS },
879 { "tis620", RTL_TEXTENCODING_TIS_620 },
880 { "gbk", RTL_TEXTENCODING_GBK },
881 { "cp936", RTL_TEXTENCODING_GBK },
882 { "ms936", RTL_TEXTENCODING_GBK },
883 { "windows936", RTL_TEXTENCODING_GBK },
884 { "cp874", RTL_TEXTENCODING_MS_874 },
885 /* This is no official MIME character set name, but it might be in
886 use in Thailand. */
887 { "ms874", RTL_TEXTENCODING_MS_874 },
888 /* This is no official MIME character set name, but it might be in
889 use in Thailand. */
890 { "windows874", RTL_TEXTENCODING_MS_874 },
891 /* This is no official MIME character set name, but it might be in
892 use in Thailand. */
893 { "koi8u", RTL_TEXTENCODING_KOI8_U },
894 { "cpis", RTL_TEXTENCODING_IBM_861 },
895 { "ksc56011987", RTL_TEXTENCODING_MS_949 },
896 { "isoir149", RTL_TEXTENCODING_MS_949 },
897 { "ksc56011989", RTL_TEXTENCODING_MS_949 },
898 { "ksc5601", RTL_TEXTENCODING_MS_949 },
899 { "korean", RTL_TEXTENCODING_MS_949 },
900 { "csksc56011987", RTL_TEXTENCODING_MS_949 },
901 /* Map KS_C_5601-1987 and aliases to MS-949 instead of EUC-KR, as
902 this character set identifier seems to be prominently used by MS
903 to stand for KS C 5601 plus MS-949 extensions */
904 { "latin9", RTL_TEXTENCODING_ISO_8859_15 },
905 { "adobestandardencoding", RTL_TEXTENCODING_ADOBE_STANDARD },
906 { "csadobestandardencoding", RTL_TEXTENCODING_ADOBE_STANDARD },
907 { "adobesymbolencoding", RTL_TEXTENCODING_ADOBE_SYMBOL },
908 { "cshppsmath", RTL_TEXTENCODING_ADOBE_SYMBOL },
909 { "ptcp154", RTL_TEXTENCODING_PT154 },
910 { "csptcp154", RTL_TEXTENCODING_PT154 },
911 { "pt154", RTL_TEXTENCODING_PT154 },
912 { "cp154", RTL_TEXTENCODING_PT154 },
913 { "xisciide", RTL_TEXTENCODING_ISCII_DEVANAGARI },
914 /* This is no official MIME character set name, but is in use by
915 various windows APIs. */
916 { NULL, RTL_TEXTENCODING_DONTKNOW }
919 rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
920 sal_Char* pBuf;
921 const ImplStrCharsetDef* pData = aVIPMimeCharsetTab;
922 sal_uInt32 nBufLen = strlen( pMimeCharset )+1;
924 /* Alloc Buffer and map to lower case and remove non alphanumeric chars */
925 pBuf = (char*)rtl_allocateMemory( nBufLen );
926 Impl_toAsciiLowerAndRemoveNonAlphanumeric( pMimeCharset, pBuf );
928 /* Search for equal in the VIP table */
929 while ( pData->mpCharsetStr )
931 if ( strcmp( pBuf, pData->mpCharsetStr ) == 0 )
933 eEncoding = pData->meTextEncoding;
934 break;
937 pData++;
940 /* Search for matching in the mime table */
941 if ( eEncoding == RTL_TEXTENCODING_DONTKNOW )
943 pData = aMimeCharsetTab;
944 while ( pData->mpCharsetStr )
946 if ( Impl_matchString( pBuf, pData->mpCharsetStr ) )
948 eEncoding = pData->meTextEncoding;
949 break;
952 pData++;
956 rtl_freeMemory( pBuf );
958 return eEncoding;
961 /* ======================================================================= */
963 sal_uInt8 SAL_CALL rtl_getBestWindowsCharsetFromTextEncoding( rtl_TextEncoding eTextEncoding )
965 const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
966 if ( pData )
967 return pData->mnBestWindowsCharset;
968 else
969 return 1;
972 /* ----------------------------------------------------------------------- */
974 const sal_Char* SAL_CALL rtl_getBestUnixCharsetFromTextEncoding( rtl_TextEncoding eTextEncoding )
976 const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
977 if ( pData )
978 return (sal_Char const *) pData->mpBestUnixCharset;
979 else if( eTextEncoding == RTL_TEXTENCODING_UNICODE )
980 return (sal_Char const *) "iso10646-1";
981 else
982 return 0;
985 /* ----------------------------------------------------------------------- */
987 char const * SAL_CALL rtl_getMimeCharsetFromTextEncoding(rtl_TextEncoding
988 nEncoding)
990 ImplTextEncodingData const * p = Impl_getTextEncodingData(nEncoding);
991 return p && (p->mnInfoFlags & RTL_TEXTENCODING_INFO_MIME) != 0 ?
992 p->mpBestMimeCharset : NULL;
995 const sal_Char* SAL_CALL rtl_getBestMimeCharsetFromTextEncoding( rtl_TextEncoding eTextEncoding )
997 const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
998 if ( pData )
999 return (sal_Char const *) pData->mpBestMimeCharset;
1000 else
1001 return 0;
1004 /* The following two functions are based on <http://www.sharmahd.com/tm/
1005 codepages.html>, <http://msdn.microsoft.com/workshop/author/dhtml/reference/
1006 charsets/charset4.asp>, and <http://www.iana.org/assignments/character-sets>.
1009 rtl_TextEncoding SAL_CALL
1010 rtl_getTextEncodingFromWindowsCodePage(sal_uInt32 nCodePage)
1012 switch (nCodePage)
1014 case 437: return RTL_TEXTENCODING_IBM_437;
1015 case 708: return RTL_TEXTENCODING_ISO_8859_6;
1016 case 737: return RTL_TEXTENCODING_IBM_737;
1017 case 775: return RTL_TEXTENCODING_IBM_775;
1018 case 850: return RTL_TEXTENCODING_IBM_850;
1019 case 852: return RTL_TEXTENCODING_IBM_852;
1020 case 855: return RTL_TEXTENCODING_IBM_855;
1021 case 857: return RTL_TEXTENCODING_IBM_857;
1022 case 860: return RTL_TEXTENCODING_IBM_860;
1023 case 861: return RTL_TEXTENCODING_IBM_861;
1024 case 862: return RTL_TEXTENCODING_IBM_862;
1025 case 863: return RTL_TEXTENCODING_IBM_863;
1026 case 864: return RTL_TEXTENCODING_IBM_864;
1027 case 865: return RTL_TEXTENCODING_IBM_865;
1028 case 866: return RTL_TEXTENCODING_IBM_866;
1029 case 869: return RTL_TEXTENCODING_IBM_869;
1030 case 874: return RTL_TEXTENCODING_MS_874;
1031 case 932: return RTL_TEXTENCODING_MS_932;
1032 case 936: return RTL_TEXTENCODING_MS_936;
1033 case 949: return RTL_TEXTENCODING_MS_949;
1034 case 950: return RTL_TEXTENCODING_MS_950;
1035 case 1250: return RTL_TEXTENCODING_MS_1250;
1036 case 1251: return RTL_TEXTENCODING_MS_1251;
1037 case 1252: return RTL_TEXTENCODING_MS_1252;
1038 case 1253: return RTL_TEXTENCODING_MS_1253;
1039 case 1254: return RTL_TEXTENCODING_MS_1254;
1040 case 1255: return RTL_TEXTENCODING_MS_1255;
1041 case 1256: return RTL_TEXTENCODING_MS_1256;
1042 case 1257: return RTL_TEXTENCODING_MS_1257;
1043 case 1258: return RTL_TEXTENCODING_MS_1258;
1044 case 1361: return RTL_TEXTENCODING_MS_1361;
1045 case 10000: return RTL_TEXTENCODING_APPLE_ROMAN;
1046 case 10001: return RTL_TEXTENCODING_APPLE_JAPANESE;
1047 case 10002: return RTL_TEXTENCODING_APPLE_CHINTRAD;
1048 case 10003: return RTL_TEXTENCODING_APPLE_KOREAN;
1049 case 10004: return RTL_TEXTENCODING_APPLE_ARABIC;
1050 case 10005: return RTL_TEXTENCODING_APPLE_HEBREW;
1051 case 10006: return RTL_TEXTENCODING_APPLE_GREEK;
1052 case 10007: return RTL_TEXTENCODING_APPLE_CYRILLIC;
1053 case 10008: return RTL_TEXTENCODING_APPLE_CHINSIMP;
1054 case 10010: return RTL_TEXTENCODING_APPLE_ROMANIAN;
1055 case 10017: return RTL_TEXTENCODING_APPLE_UKRAINIAN;
1056 case 10029: return RTL_TEXTENCODING_APPLE_CENTEURO;
1057 case 10079: return RTL_TEXTENCODING_APPLE_ICELAND;
1058 case 10081: return RTL_TEXTENCODING_APPLE_TURKISH;
1059 case 10082: return RTL_TEXTENCODING_APPLE_CROATIAN;
1060 case 20127: return RTL_TEXTENCODING_ASCII_US;
1061 case 20866: return RTL_TEXTENCODING_KOI8_R;
1062 case 21866: return RTL_TEXTENCODING_KOI8_U;
1063 case 28591: return RTL_TEXTENCODING_ISO_8859_1;
1064 case 28592: return RTL_TEXTENCODING_ISO_8859_2;
1065 case 28593: return RTL_TEXTENCODING_ISO_8859_3;
1066 case 28594: return RTL_TEXTENCODING_ISO_8859_4;
1067 case 28595: return RTL_TEXTENCODING_ISO_8859_5;
1068 case 28596: return RTL_TEXTENCODING_ISO_8859_6;
1069 case 28597: return RTL_TEXTENCODING_ISO_8859_7;
1070 case 28598: return RTL_TEXTENCODING_ISO_8859_8;
1071 case 28599: return RTL_TEXTENCODING_ISO_8859_9;
1072 case 28605: return RTL_TEXTENCODING_ISO_8859_15;
1073 case 50220: return RTL_TEXTENCODING_ISO_2022_JP;
1074 case 50225: return RTL_TEXTENCODING_ISO_2022_KR;
1075 case 51932: return RTL_TEXTENCODING_EUC_JP;
1076 case 51936: return RTL_TEXTENCODING_EUC_CN;
1077 case 51949: return RTL_TEXTENCODING_EUC_KR;
1078 case 57002: return RTL_TEXTENCODING_ISCII_DEVANAGARI;
1079 case 65000: return RTL_TEXTENCODING_UTF7;
1080 case 65001: return RTL_TEXTENCODING_UTF8;
1081 default: return RTL_TEXTENCODING_DONTKNOW;
1085 sal_uInt32 SAL_CALL
1086 rtl_getWindowsCodePageFromTextEncoding(rtl_TextEncoding nEncoding)
1088 switch (nEncoding)
1090 case RTL_TEXTENCODING_IBM_437: return 437;
1091 /* case RTL_TEXTENCODING_ISO_8859_6: return 708; */
1092 case RTL_TEXTENCODING_IBM_737: return 737;
1093 case RTL_TEXTENCODING_IBM_775: return 775;
1094 case RTL_TEXTENCODING_IBM_850: return 850;
1095 case RTL_TEXTENCODING_IBM_852: return 852;
1096 case RTL_TEXTENCODING_IBM_855: return 855;
1097 case RTL_TEXTENCODING_IBM_857: return 857;
1098 case RTL_TEXTENCODING_IBM_860: return 860;
1099 case RTL_TEXTENCODING_IBM_861: return 861;
1100 case RTL_TEXTENCODING_IBM_862: return 862;
1101 case RTL_TEXTENCODING_IBM_863: return 863;
1102 case RTL_TEXTENCODING_IBM_864: return 864;
1103 case RTL_TEXTENCODING_IBM_865: return 865;
1104 case RTL_TEXTENCODING_IBM_866: return 866;
1105 case RTL_TEXTENCODING_IBM_869: return 869;
1106 case RTL_TEXTENCODING_MS_874: return 874;
1107 case RTL_TEXTENCODING_MS_932: return 932;
1108 case RTL_TEXTENCODING_MS_936: return 936;
1109 case RTL_TEXTENCODING_MS_949: return 949;
1110 case RTL_TEXTENCODING_MS_950: return 950;
1111 case RTL_TEXTENCODING_MS_1250: return 1250;
1112 case RTL_TEXTENCODING_MS_1251: return 1251;
1113 case RTL_TEXTENCODING_MS_1252: return 1252;
1114 case RTL_TEXTENCODING_MS_1253: return 1253;
1115 case RTL_TEXTENCODING_MS_1254: return 1254;
1116 case RTL_TEXTENCODING_MS_1255: return 1255;
1117 case RTL_TEXTENCODING_MS_1256: return 1256;
1118 case RTL_TEXTENCODING_MS_1257: return 1257;
1119 case RTL_TEXTENCODING_MS_1258: return 1258;
1120 case RTL_TEXTENCODING_MS_1361: return 1361;
1121 case RTL_TEXTENCODING_APPLE_ROMAN: return 10000;
1122 case RTL_TEXTENCODING_APPLE_JAPANESE: return 10001;
1123 case RTL_TEXTENCODING_APPLE_CHINTRAD: return 10002;
1124 case RTL_TEXTENCODING_APPLE_KOREAN: return 10003;
1125 case RTL_TEXTENCODING_APPLE_ARABIC: return 10004;
1126 case RTL_TEXTENCODING_APPLE_HEBREW: return 10005;
1127 case RTL_TEXTENCODING_APPLE_GREEK: return 10006;
1128 case RTL_TEXTENCODING_APPLE_CYRILLIC: return 10007;
1129 case RTL_TEXTENCODING_APPLE_CHINSIMP: return 10008;
1130 case RTL_TEXTENCODING_APPLE_ROMANIAN: return 10010;
1131 case RTL_TEXTENCODING_APPLE_UKRAINIAN: return 10017;
1132 case RTL_TEXTENCODING_APPLE_CENTEURO: return 10029;
1133 case RTL_TEXTENCODING_APPLE_ICELAND: return 10079;
1134 case RTL_TEXTENCODING_APPLE_TURKISH: return 10081;
1135 case RTL_TEXTENCODING_APPLE_CROATIAN: return 10082;
1136 case RTL_TEXTENCODING_ASCII_US: return 20127;
1137 case RTL_TEXTENCODING_KOI8_R: return 20866;
1138 case RTL_TEXTENCODING_KOI8_U: return 21866;
1139 case RTL_TEXTENCODING_ISO_8859_1: return 28591;
1140 case RTL_TEXTENCODING_ISO_8859_2: return 28592;
1141 case RTL_TEXTENCODING_ISO_8859_3: return 28593;
1142 case RTL_TEXTENCODING_ISO_8859_4: return 28594;
1143 case RTL_TEXTENCODING_ISO_8859_5: return 28595;
1144 case RTL_TEXTENCODING_ISO_8859_6: return 28596;
1145 case RTL_TEXTENCODING_ISO_8859_7: return 28597;
1146 case RTL_TEXTENCODING_ISO_8859_8: return 28598;
1147 case RTL_TEXTENCODING_ISO_8859_9: return 28599;
1148 case RTL_TEXTENCODING_ISO_8859_15: return 28605;
1149 case RTL_TEXTENCODING_ISO_2022_JP: return 50220;
1150 case RTL_TEXTENCODING_ISO_2022_KR: return 50225;
1151 case RTL_TEXTENCODING_EUC_JP: return 51932;
1152 case RTL_TEXTENCODING_EUC_CN: return 51936;
1153 case RTL_TEXTENCODING_EUC_KR: return 51949;
1154 case RTL_TEXTENCODING_ISCII_DEVANAGARI: return 57002;
1155 case RTL_TEXTENCODING_UTF7: return 65000;
1156 case RTL_TEXTENCODING_UTF8: return 65001;
1157 default: return 0;