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