xref: /trunk/main/tools/source/string/tenccvt.cxx (revision 89b56da7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26 #include <rtl/tencinfo.h>
27 #include <tools/tenccvt.hxx>
28 
29 // =======================================================================
30 
GetExtendedCompatibilityTextEncoding(rtl_TextEncoding eEncoding)31 rtl_TextEncoding GetExtendedCompatibilityTextEncoding( rtl_TextEncoding eEncoding )
32 {
33     // Latin1
34     if ( eEncoding == RTL_TEXTENCODING_ISO_8859_1 )
35         return RTL_TEXTENCODING_MS_1252;
36     // Turkey
37     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_9 )
38         return RTL_TEXTENCODING_MS_1254;
39     else
40         return eEncoding;
41 }
42 
43 // -----------------------------------------------------------------------
44 
GetExtendedTextEncoding(rtl_TextEncoding eEncoding)45 rtl_TextEncoding GetExtendedTextEncoding( rtl_TextEncoding eEncoding )
46 {
47     // Cyr
48     if ( eEncoding == RTL_TEXTENCODING_ISO_8859_5 )
49         return RTL_TEXTENCODING_MS_1251;
50     // Greek (2 Characters different: A1 (0x2018/0x0385), A2 (0x2019/0x0386) -
51     // so it is handled in this function and not in GetExtendedCompatibilityTextEncoding)
52     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_7 )
53         return RTL_TEXTENCODING_MS_1253;
54     // East-Europe - Latin2
55     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_2 )
56         return RTL_TEXTENCODING_MS_1250;
57     // Latin-15 - Latin 1 mit Euro-Sign
58     else if ( eEncoding == RTL_TEXTENCODING_ISO_8859_15 )
59         return RTL_TEXTENCODING_MS_1252;
60     else
61         return GetExtendedCompatibilityTextEncoding( eEncoding );
62 }
63 
64 // -----------------------------------------------------------------------
65 
GetOneByteTextEncoding(rtl_TextEncoding eEncoding)66 rtl_TextEncoding GetOneByteTextEncoding( rtl_TextEncoding eEncoding )
67 {
68     rtl_TextEncodingInfo aTextEncInfo;
69     aTextEncInfo.StructSize = sizeof( aTextEncInfo );
70     if ( rtl_getTextEncodingInfo( eEncoding, &aTextEncInfo ) )
71     {
72         if ( aTextEncInfo.MaximumCharSize > 1 )
73             return RTL_TEXTENCODING_MS_1252;
74         else
75             return eEncoding;
76     }
77     else
78         return RTL_TEXTENCODING_MS_1252;
79 }
80 
81 // -----------------------------------------------------------------------
82 
GetSOLoadTextEncoding(rtl_TextEncoding eEncoding,sal_uInt16)83 rtl_TextEncoding GetSOLoadTextEncoding( rtl_TextEncoding eEncoding, sal_uInt16 /* nVersion = SOFFICE_FILEFORMAT_50 */ )
84 {
85     return GetExtendedCompatibilityTextEncoding( GetOneByteTextEncoding( eEncoding ) );
86 }
87 
88 // -----------------------------------------------------------------------
89 
GetSOStoreTextEncoding(rtl_TextEncoding eEncoding,sal_uInt16)90 rtl_TextEncoding GetSOStoreTextEncoding( rtl_TextEncoding eEncoding, sal_uInt16 /* nVersion = SOFFICE_FILEFORMAT_50 */ )
91 {
92     return GetExtendedTextEncoding( GetOneByteTextEncoding( eEncoding ) );
93 }
94