Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
17 : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s): Caolán McNamara <caolanm@redhat.com>
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include "sal/config.h"
30 : #include "rtl/textcvt.h"
31 :
32 : #include <stdio.h>
33 :
34 : struct Encoder
35 : {
36 : rtl_UnicodeToTextConverter m_aConverter;
37 : bool m_bCapable;
38 : rtl_TextEncoding m_nEncoding;
39 : const char *m_pEncoding;
40 0 : Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
41 : : m_bCapable(true)
42 : , m_nEncoding(nEncoding)
43 0 : , m_pEncoding(pEncoding)
44 : {
45 0 : m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
46 0 : }
47 0 : ~Encoder()
48 : {
49 0 : rtl_destroyUnicodeToTextConverter(m_aConverter);
50 0 : }
51 0 : void checkSupports(sal_Unicode c)
52 : {
53 : sal_Char aTempArray[8];
54 : sal_Size nTempSize;
55 : sal_uInt32 nCvtInfo;
56 :
57 : sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
58 : NULL, &c, 1, aTempArray, sizeof(aTempArray),
59 : RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
60 0 : &nCvtInfo, &nTempSize);
61 0 : m_bCapable = nChars > 0;
62 0 : }
63 0 : void reset()
64 : {
65 0 : m_bCapable = true;
66 0 : }
67 0 : bool isOK() const
68 : {
69 0 : return m_bCapable;
70 : }
71 0 : const char* getName() const
72 : {
73 0 : return m_pEncoding;
74 : }
75 :
76 : };
77 :
78 0 : int main()
79 : {
80 : # define EXP(x) Encoder(x, #x)
81 :
82 : Encoder aConverters[15] =
83 : {
84 : EXP(RTL_TEXTENCODING_MS_1361),
85 : EXP(RTL_TEXTENCODING_MS_950),
86 : EXP(RTL_TEXTENCODING_MS_949),
87 : EXP(RTL_TEXTENCODING_MS_936),
88 : EXP(RTL_TEXTENCODING_MS_932),
89 : EXP(RTL_TEXTENCODING_MS_874),
90 : EXP(RTL_TEXTENCODING_MS_1258),
91 : EXP(RTL_TEXTENCODING_MS_1257),
92 : EXP(RTL_TEXTENCODING_MS_1256),
93 : EXP(RTL_TEXTENCODING_MS_1255),
94 : EXP(RTL_TEXTENCODING_MS_1254),
95 : EXP(RTL_TEXTENCODING_MS_1253),
96 : EXP(RTL_TEXTENCODING_MS_1251),
97 : EXP(RTL_TEXTENCODING_MS_1250),
98 : EXP(RTL_TEXTENCODING_MS_1252)
99 0 : };
100 :
101 0 : printf("//Do not edit manually, generated from bestreversemap.cxx\n");
102 0 : printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
103 0 : printf("{\n");
104 :
105 0 : sal_Unicode c = 0;
106 0 : while (c < 0xFFFF)
107 : {
108 0 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
109 0 : aConverters[i].reset();
110 :
111 0 : int nMostCapable = -1;
112 :
113 0 : while(c < 0xFFFF)
114 : {
115 0 : bool bSomethingCapable = false;
116 0 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
117 : {
118 0 : if (aConverters[i].isOK())
119 0 : aConverters[i].checkSupports(c);
120 0 : if (aConverters[i].isOK())
121 : {
122 0 : bSomethingCapable = true;
123 0 : nMostCapable = i;
124 : }
125 : }
126 0 : if (!bSomethingCapable)
127 0 : break;
128 0 : ++c;
129 : }
130 0 : sal_Unicode cEnd = c;
131 0 : printf(" if (c < 0x%x)\n", c);
132 0 : printf(" return %s;\n", aConverters[nMostCapable].getName());
133 0 : while(c < 0xFFFF)
134 : {
135 0 : bool bNothingCapable = true;
136 0 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
137 : {
138 0 : aConverters[i].checkSupports(c);
139 0 : if (aConverters[i].isOK())
140 : {
141 0 : bNothingCapable = false;
142 0 : break;
143 : }
144 : }
145 0 : if (!bNothingCapable)
146 0 : break;
147 0 : ++c;
148 : }
149 0 : if (cEnd != c)
150 : {
151 0 : if (c < 0xFFFF)
152 : {
153 0 : printf(" if (c < 0x%x)\n", c);
154 0 : printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
155 : }
156 : else
157 0 : printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
158 : }
159 : }
160 :
161 0 : printf("}\n");
162 0 : fflush(stdout);
163 :
164 0 : return EXIT_SUCCESS;
165 : }
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|