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>
18 rtl_UnicodeToTextConverter
const m_aConverter
;
20 const char *m_pEncoding
;
21 Encoder(rtl_TextEncoding nEncoding
, const char *pEncoding
)
22 : m_aConverter(rtl_createUnicodeToTextConverter(nEncoding
))
24 , m_pEncoding(pEncoding
)
29 rtl_destroyUnicodeToTextConverter(m_aConverter
);
31 void checkSupports(sal_Unicode c
)
33 sal_Char aTempArray
[8];
37 sal_Size nChars
= rtl_convertUnicodeToText(m_aConverter
,
38 nullptr, &c
, 1, aTempArray
, sizeof(aTempArray
),
39 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
| RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
,
40 &nCvtInfo
, &nTempSize
);
41 m_bCapable
= nChars
> 0;
51 const char* getName() const
60 # define EXP(x) Encoder(x, #x)
62 Encoder aConverters
[15] =
64 EXP(RTL_TEXTENCODING_MS_1361
),
65 EXP(RTL_TEXTENCODING_MS_950
),
66 EXP(RTL_TEXTENCODING_MS_949
),
67 EXP(RTL_TEXTENCODING_MS_936
),
68 EXP(RTL_TEXTENCODING_MS_932
),
69 EXP(RTL_TEXTENCODING_MS_874
),
70 EXP(RTL_TEXTENCODING_MS_1258
),
71 EXP(RTL_TEXTENCODING_MS_1257
),
72 EXP(RTL_TEXTENCODING_MS_1256
),
73 EXP(RTL_TEXTENCODING_MS_1255
),
74 EXP(RTL_TEXTENCODING_MS_1254
),
75 EXP(RTL_TEXTENCODING_MS_1253
),
76 EXP(RTL_TEXTENCODING_MS_1251
),
77 EXP(RTL_TEXTENCODING_MS_1250
),
78 EXP(RTL_TEXTENCODING_MS_1252
)
81 printf("//Do not edit manually, generated from bestreversemap.cxx\n");
82 printf("#include <rtl/textenc.h>\n");
83 printf("#include <tools/tenccvt.hxx>\n");
84 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
90 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
91 aConverters
[i
].reset();
93 int nMostCapable
= -1;
97 bool bSomethingCapable
= false;
98 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
100 if (aConverters
[i
].isOK())
101 aConverters
[i
].checkSupports(c
);
102 if (aConverters
[i
].isOK())
104 bSomethingCapable
= true;
108 if (!bSomethingCapable
)
112 sal_Unicode cEnd
= c
;
113 printf(" if (c < 0x%x)\n", c
);
114 printf(" return %s;\n", aConverters
[nMostCapable
].getName());
117 bool bNothingCapable
= true;
118 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
120 aConverters
[i
].checkSupports(c
);
121 if (aConverters
[i
].isOK())
123 bNothingCapable
= false;
127 if (!bNothingCapable
)
135 printf(" if (c < 0x%x)\n", c
);
136 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
139 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */