xref: /aoo42x/main/l10ntools/source/utf8conv.cxx (revision 3adb8b6e)
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_l10ntools.hxx"
26 #include "utf8conv.hxx"
27 
28 //
29 // class UTF8Converter
30 //
31 
32 #define MAX_CONV_BUFFER_SIZE	0xFF00
33 
34 #define TO_CVTFLAGS		(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE |\
35 			 			 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |\
36 			 			 RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT)
37 
38 #define FROM_CVTFLAGS	(RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |\
39 						 RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |\
40 						 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |\
41 						 RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0)
42 
43 /*****************************************************************************/
Convert(ByteString & rBuffer,rtl_TextEncoding nSourceENC,rtl_TextEncoding nDestENC)44 void UTF8Converter::Convert( ByteString &rBuffer,
45 	rtl_TextEncoding nSourceENC, rtl_TextEncoding nDestENC )
46 /*****************************************************************************/
47 {
48 	String sTemp( rBuffer, nSourceENC );
49 	rBuffer = ByteString( sTemp, nDestENC );
50 }
51 
52 /*****************************************************************************/
ConvertToUTF8(const ByteString & rASCII,rtl_TextEncoding nEncoding)53 ByteString UTF8Converter::ConvertToUTF8(
54 	const ByteString &rASCII, rtl_TextEncoding nEncoding )
55 /*****************************************************************************/
56 {
57 	ByteString sReturn( rASCII );
58 	Convert( sReturn, nEncoding, RTL_TEXTENCODING_UTF8 );
59 	return sReturn;
60 }
61 
62 /*****************************************************************************/
ConvertFromUTF8(const ByteString & rUTF8,rtl_TextEncoding nEncoding)63 ByteString UTF8Converter::ConvertFromUTF8(
64 	const ByteString &rUTF8, rtl_TextEncoding nEncoding )
65 /*****************************************************************************/
66 {
67 	ByteString sReturn( rUTF8 );
68 	Convert( sReturn, RTL_TEXTENCODING_UTF8, nEncoding );
69 	return sReturn;
70 }
71