bump product version to 4.1.6.2
[LibreOffice.git] / tools / source / reversemap / bestreversemap.cxx
blob9beeb367d36eea4691fffca3a5cd8e403d74e49a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "sal/config.h"
11 #include "rtl/textcvt.h"
13 #include <stdio.h>
15 struct Encoder
17 rtl_UnicodeToTextConverter m_aConverter;
18 bool m_bCapable;
19 rtl_TextEncoding m_nEncoding;
20 const char *m_pEncoding;
21 Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
22 : m_bCapable(true)
23 , m_nEncoding(nEncoding)
24 , m_pEncoding(pEncoding)
26 m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
28 ~Encoder()
30 rtl_destroyUnicodeToTextConverter(m_aConverter);
32 void checkSupports(sal_Unicode c)
34 sal_Char aTempArray[8];
35 sal_Size nTempSize;
36 sal_uInt32 nCvtInfo;
38 sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
39 NULL, &c, 1, aTempArray, sizeof(aTempArray),
40 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
41 &nCvtInfo, &nTempSize);
42 m_bCapable = nChars > 0;
44 void reset()
46 m_bCapable = true;
48 bool isOK() const
50 return m_bCapable;
52 const char* getName() const
54 return m_pEncoding;
59 int main()
61 # define EXP(x) Encoder(x, #x)
63 Encoder aConverters[15] =
65 EXP(RTL_TEXTENCODING_MS_1361),
66 EXP(RTL_TEXTENCODING_MS_950),
67 EXP(RTL_TEXTENCODING_MS_949),
68 EXP(RTL_TEXTENCODING_MS_936),
69 EXP(RTL_TEXTENCODING_MS_932),
70 EXP(RTL_TEXTENCODING_MS_874),
71 EXP(RTL_TEXTENCODING_MS_1258),
72 EXP(RTL_TEXTENCODING_MS_1257),
73 EXP(RTL_TEXTENCODING_MS_1256),
74 EXP(RTL_TEXTENCODING_MS_1255),
75 EXP(RTL_TEXTENCODING_MS_1254),
76 EXP(RTL_TEXTENCODING_MS_1253),
77 EXP(RTL_TEXTENCODING_MS_1251),
78 EXP(RTL_TEXTENCODING_MS_1250),
79 EXP(RTL_TEXTENCODING_MS_1252)
82 printf("//Do not edit manually, generated from bestreversemap.cxx\n");
83 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
84 printf("{\n");
86 sal_Unicode c = 0;
87 while (c < 0xFFFF)
89 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
90 aConverters[i].reset();
92 int nMostCapable = -1;
94 while(c < 0xFFFF)
96 bool bSomethingCapable = false;
97 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
99 if (aConverters[i].isOK())
100 aConverters[i].checkSupports(c);
101 if (aConverters[i].isOK())
103 bSomethingCapable = true;
104 nMostCapable = i;
107 if (!bSomethingCapable)
108 break;
109 ++c;
111 sal_Unicode cEnd = c;
112 printf(" if (c < 0x%x)\n", c);
113 printf(" return %s;\n", aConverters[nMostCapable].getName());
114 while(c < 0xFFFF)
116 bool bNothingCapable = true;
117 for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
119 aConverters[i].checkSupports(c);
120 if (aConverters[i].isOK())
122 bNothingCapable = false;
123 break;
126 if (!bNothingCapable)
127 break;
128 ++c;
130 if (cEnd != c)
132 if (c < 0xFFFF)
134 printf(" if (c < 0x%x)\n", c);
135 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
137 else
138 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
142 printf("}\n");
143 fflush(stdout);
145 return EXIT_SUCCESS;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */