Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : */
12 :
13 : #include "sal/config.h"
14 : #include "rtl/textcvt.h"
15 :
16 : #include <stdio.h>
17 :
18 : struct Encoder
19 : {
20 : rtl_UnicodeToTextConverter m_aConverter;
21 : bool m_bCapable;
22 : rtl_TextEncoding m_nEncoding;
23 : const char *m_pEncoding;
24 15 : Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
25 : : m_bCapable(true)
26 : , m_nEncoding(nEncoding)
27 15 : , m_pEncoding(pEncoding)
28 : {
29 15 : m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
30 15 : }
31 15 : ~Encoder()
32 : {
33 15 : rtl_destroyUnicodeToTextConverter(m_aConverter);
34 15 : }
35 437543 : void checkSupports(sal_Unicode c)
36 : {
37 : sal_Char aTempArray[8];
38 : sal_Size nTempSize;
39 : sal_uInt32 nCvtInfo;
40 :
41 : sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
42 : NULL, &c, 1, aTempArray, sizeof(aTempArray),
43 : RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
44 437543 : &nCvtInfo, &nTempSize);
45 437543 : m_bCapable = nChars > 0;
46 437543 : }
47 3855 : void reset()
48 : {
49 3855 : m_bCapable = true;
50 3855 : }
51 1601213 : bool isOK() const
52 : {
53 1601213 : return m_bCapable;
54 : }
55 257 : const char* getName() const
56 : {
57 257 : return m_pEncoding;
58 : }
59 :
60 : };
61 :
62 1 : int main()
63 : {
64 : # define EXP(x) Encoder(x, #x)
65 :
66 : Encoder aConverters[15] =
67 : {
68 : EXP(RTL_TEXTENCODING_MS_1361),
69 : EXP(RTL_TEXTENCODING_MS_950),
70 : EXP(RTL_TEXTENCODING_MS_949),
71 : EXP(RTL_TEXTENCODING_MS_936),
72 : EXP(RTL_TEXTENCODING_MS_932),
73 : EXP(RTL_TEXTENCODING_MS_874),
74 : EXP(RTL_TEXTENCODING_MS_1258),
75 : EXP(RTL_TEXTENCODING_MS_1257),
76 : EXP(RTL_TEXTENCODING_MS_1256),
77 : EXP(RTL_TEXTENCODING_MS_1255),
78 : EXP(RTL_TEXTENCODING_MS_1254),
79 : EXP(RTL_TEXTENCODING_MS_1253),
80 : EXP(RTL_TEXTENCODING_MS_1251),
81 : EXP(RTL_TEXTENCODING_MS_1250),
82 : EXP(RTL_TEXTENCODING_MS_1252)
83 16 : };
84 :
85 1 : printf("//Do not edit manually, generated from bestreversemap.cxx\n");
86 1 : printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
87 1 : printf("{\n");
88 :
89 1 : sal_Unicode c = 0;
90 259 : while (c < 0xFFFF)
91 : {
92 4112 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
93 3855 : aConverters[i].reset();
94 :
95 257 : int nMostCapable = -1;
96 :
97 41142 : while(c < 0xFFFF)
98 : {
99 40885 : bool bSomethingCapable = false;
100 654160 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
101 : {
102 613275 : if (aConverters[i].isOK())
103 62880 : aConverters[i].checkSupports(c);
104 613275 : if (aConverters[i].isOK())
105 : {
106 59025 : bSomethingCapable = true;
107 59025 : nMostCapable = i;
108 : }
109 : }
110 40885 : if (!bSomethingCapable)
111 257 : break;
112 40628 : ++c;
113 : }
114 257 : sal_Unicode cEnd = c;
115 257 : printf(" if (c < 0x%x)\n", c);
116 257 : printf(" return %s;\n", aConverters[nMostCapable].getName());
117 25421 : while(c < 0xFFFF)
118 : {
119 25163 : bool bNothingCapable = true;
120 399570 : for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
121 : {
122 374663 : aConverters[i].checkSupports(c);
123 374663 : if (aConverters[i].isOK())
124 : {
125 256 : bNothingCapable = false;
126 256 : break;
127 : }
128 : }
129 25163 : if (!bNothingCapable)
130 256 : break;
131 24907 : ++c;
132 : }
133 257 : if (cEnd != c)
134 : {
135 211 : if (c < 0xFFFF)
136 : {
137 210 : printf(" if (c < 0x%x)\n", c);
138 210 : printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
139 : }
140 : else
141 1 : printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
142 : }
143 : }
144 :
145 1 : printf("}\n");
146 1 : fflush(stdout);
147 :
148 16 : return EXIT_SUCCESS;
149 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|