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 #ifndef INCLUDED_sal_textenc_convertsinglebytetobmpunicode_hxx
25 #define INCLUDED_sal_textenc_convertsinglebytetobmpunicode_hxx
26 
27 #include "tenchelp.h"
28 
29 #include "sal/types.h"
30 
31 #include <cstddef>
32 
33 /// @HTML
34 
35 namespace rtl { namespace textenc {
36 
37 /**
38    Maps a range of BMP Unicode code points to individual bytes.
39 
40    @see rtl::textenc::BmpUnicodeToSingleByteConverterData
41  */
42 struct BmpUnicodeToSingleByteRange {
43     /**
44        The start of the range of BMP Unicode code points.
45      */
46     sal_Unicode unicode;
47 
48     /**
49        The extend of the range of BMP Unicode code points.
50 
51        <p>The range covers <code>unicode</code> to <code>unicode + range</code>,
52        inclusive.  It is an error if <code>unicode + range</code> is greater
53        than <code>0xFFFF</code>.</p>
54      */
55     sal_uInt8 range;
56 
57     /**
58        The start of the corresponding range of individual bytes.
59 
60        <p>It is an error if <code>byte + range</code> is greater than
61        <code>0xFF</code>.</p>
62      */
63     sal_uInt8 byte;
64 };
65 
66 /**
67    Data to convert between BMP Unicode and a single-byte character set.
68 
69    <p>Only supports conversions where each legal unit from the single-byte
70    character set has one or more mappings to individual BMP Unicode code points
71    that are neither noncharacters nor surrogates.</p>
72 
73    @see rtl_textenc_convertSingleByteToBmpUnicode
74    @see rtl_textenc_convertBmpUnicodeToSingleByte
75  */
76 struct BmpUnicodeToSingleByteConverterData {
77     /**
78        Mapping from the single-byte character set to BMP Unicode code points.
79 
80        <p>Illegal units from the single-byte character set are mapped to
81        <code>0xFFFF</code>.</p>
82      */
83     sal_Unicode byteToUnicode[256];
84 
85     /**
86        The number of Unicode-to-byte conversion ranges.
87      */
88     std::size_t unicodeToByteEntries;
89 
90     /**
91        The array of Unicode-to-byte conversion ranges, sorted by increasing
92        <code>unicode</code> values.
93 
94        <p>The ranges may not overlap.</p>
95      */
96     BmpUnicodeToSingleByteRange const * unicodeToByte;
97 };
98 
99 } }
100 
101 /**
102    Function to convert from a single-byte character set to BMP Unicode.
103 
104    @see ImplConvertToUnicodeProc
105  */
106 extern "C" sal_Size rtl_textenc_convertSingleByteToBmpUnicode(
107     ImplTextConverterData const * data, void * context, sal_Char const * srcBuf,
108     sal_Size srcBytes, sal_Unicode * destBuf, sal_Size destChars,
109     sal_uInt32 flags, sal_uInt32 * info, sal_Size * srcCvtBytes);
110 
111 /**
112    Function to convert from BMP Unicode to a single-byte character set.
113 
114    @see ImplConvertToTextProc
115  */
116 extern "C" sal_Size rtl_textenc_convertBmpUnicodeToSingleByte(
117     ImplTextConverterData const * data, void * context,
118     sal_Unicode const * srcBuf, sal_Size srcChars, sal_Char * destBuf,
119     sal_Size destBytes, sal_uInt32 flags, sal_uInt32 * info,
120     sal_Size * srcCvtChars);
121 
122 #endif
123