1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
11 #include <rtl/textcvt.h>
20 rtl_UnicodeToTextConverter m_aConverter
;
22 const char *m_pEncoding
;
23 Encoder(rtl_TextEncoding nEncoding
, const char *pEncoding
)
24 : m_aConverter(rtl_createUnicodeToTextConverter(nEncoding
))
26 , m_pEncoding(pEncoding
)
31 rtl_destroyUnicodeToTextConverter(m_aConverter
);
33 void checkSupports(sal_Unicode c
)
39 sal_Size nChars
= rtl_convertUnicodeToText(m_aConverter
,
40 nullptr, &c
, 1, aTempArray
, sizeof(aTempArray
),
41 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
| RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
,
42 &nCvtInfo
, &nTempSize
);
43 m_bCapable
= nChars
> 0;
53 const char* getName() const
64 # define EXP(x) Encoder(x, #x)
66 Encoder aConverters
[15] =
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
)
85 printf("//Do not edit manually, generated from bestreversemap.cxx\n");
86 printf("#include <rtl/textenc.h>\n");
87 printf("#include <tools/tenccvt.hxx>\n");
88 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
94 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
95 aConverters
[i
].reset();
97 int nMostCapable
= -1;
101 bool bSomethingCapable
= false;
102 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
104 if (aConverters
[i
].isOK())
105 aConverters
[i
].checkSupports(c
);
106 if (aConverters
[i
].isOK())
108 bSomethingCapable
= true;
112 if (!bSomethingCapable
)
116 sal_Unicode cEnd
= c
;
117 printf(" if (c < 0x%x)\n", c
);
118 printf(" return %s;\n", aConverters
[nMostCapable
].getName());
121 bool bNothingCapable
= true;
122 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
124 aConverters
[i
].checkSupports(c
);
125 if (aConverters
[i
].isOK())
127 bNothingCapable
= false;
131 if (!bNothingCapable
)
139 printf(" if (c < 0x%x)\n", c
);
140 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
143 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */