xref: /aoo41x/main/tools/source/string/tenccvt.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_tools.hxx"
30 #include <rtl/tencinfo.h>
31 #include <tools/tenccvt.hxx>
32 
33 // =======================================================================
34 
35 rtl_TextEncoding GetExtendedCompatibilityTextEncoding( rtl_TextEncoding eEncoding )
36 {
37     // Latin1
38     if ( eEncoding == RTL_TEXTENCODING_ISO_8859_1 )
39         return RTL_TEXTENCODING_MS_1252;
40     // Turkey
41     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_9 )
42         return RTL_TEXTENCODING_MS_1254;
43     else
44         return eEncoding;
45 }
46 
47 // -----------------------------------------------------------------------
48 
49 rtl_TextEncoding GetExtendedTextEncoding( rtl_TextEncoding eEncoding )
50 {
51     // Cyr
52     if ( eEncoding == RTL_TEXTENCODING_ISO_8859_5 )
53         return RTL_TEXTENCODING_MS_1251;
54     // Greek (2 Characters different: A1 (0x2018/0x0385), A2 (0x2019/0x0386) -
55     // so it is handled in this function and not in GetExtendedCompatibilityTextEncoding)
56     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_7 )
57         return RTL_TEXTENCODING_MS_1253;
58     // East-Europe - Latin2
59     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_2 )
60         return RTL_TEXTENCODING_MS_1250;
61     // Latin-15 - Latin 1 mit Euro-Sign
62     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_15 )
63         return RTL_TEXTENCODING_MS_1252;
64     else
65         return GetExtendedCompatibilityTextEncoding( eEncoding );
66 }
67 
68 // -----------------------------------------------------------------------
69 
70 rtl_TextEncoding GetOneByteTextEncoding( rtl_TextEncoding eEncoding )
71 {
72     rtl_TextEncodingInfo aTextEncInfo;
73     aTextEncInfo.StructSize = sizeof( aTextEncInfo );
74     if ( rtl_getTextEncodingInfo( eEncoding, &aTextEncInfo ) )
75     {
76         if ( aTextEncInfo.MaximumCharSize > 1 )
77             return RTL_TEXTENCODING_MS_1252;
78         else
79             return eEncoding;
80     }
81     else
82         return RTL_TEXTENCODING_MS_1252;
83 }
84 
85 // -----------------------------------------------------------------------
86 
87 rtl_TextEncoding GetSOLoadTextEncoding( rtl_TextEncoding eEncoding, sal_uInt16 /* nVersion = SOFFICE_FILEFORMAT_50 */ )
88 {
89     return GetExtendedCompatibilityTextEncoding( GetOneByteTextEncoding( eEncoding ) );
90 }
91 
92 // -----------------------------------------------------------------------
93 
94 rtl_TextEncoding GetSOStoreTextEncoding( rtl_TextEncoding eEncoding, sal_uInt16 /* nVersion = SOFFICE_FILEFORMAT_50 */ )
95 {
96     return GetExtendedTextEncoding( GetOneByteTextEncoding( eEncoding ) );
97 }
98