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>
21 rtl_UnicodeToTextConverter m_aConverter
;
23 const char *m_pEncoding
;
24 Encoder(rtl_TextEncoding nEncoding
, const char *pEncoding
)
25 : m_aConverter(rtl_createUnicodeToTextConverter(nEncoding
))
27 , m_pEncoding(pEncoding
)
32 rtl_destroyUnicodeToTextConverter(m_aConverter
);
34 void checkSupports(sal_Unicode c
)
40 sal_Size nChars
= rtl_convertUnicodeToText(m_aConverter
,
41 nullptr, &c
, 1, aTempArray
, sizeof(aTempArray
),
42 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
| RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
,
43 &nCvtInfo
, &nTempSize
);
44 m_bCapable
= nChars
> 0;
54 const char* getName() const
65 # define EXP(x) Encoder(x, #x)
67 Encoder aConverters
[15] =
69 EXP(RTL_TEXTENCODING_MS_1361
),
70 EXP(RTL_TEXTENCODING_MS_950
),
71 EXP(RTL_TEXTENCODING_MS_949
),
72 EXP(RTL_TEXTENCODING_MS_936
),
73 EXP(RTL_TEXTENCODING_MS_932
),
74 EXP(RTL_TEXTENCODING_MS_874
),
75 EXP(RTL_TEXTENCODING_MS_1258
),
76 EXP(RTL_TEXTENCODING_MS_1257
),
77 EXP(RTL_TEXTENCODING_MS_1256
),
78 EXP(RTL_TEXTENCODING_MS_1255
),
79 EXP(RTL_TEXTENCODING_MS_1254
),
80 EXP(RTL_TEXTENCODING_MS_1253
),
81 EXP(RTL_TEXTENCODING_MS_1251
),
82 EXP(RTL_TEXTENCODING_MS_1250
),
83 EXP(RTL_TEXTENCODING_MS_1252
)
86 printf("//Do not edit manually, generated from bestreversemap.cxx\n");
87 printf("#include <rtl/textenc.h>\n");
88 printf("#include <tools/tenccvt.hxx>\n");
89 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
95 for (size_t i
= 0; i
< std::size(aConverters
); ++i
)
96 aConverters
[i
].reset();
98 int nMostCapable
= -1;
102 bool bSomethingCapable
= false;
103 for (size_t i
= 0; i
< std::size(aConverters
); ++i
)
105 if (aConverters
[i
].isOK())
106 aConverters
[i
].checkSupports(c
);
107 if (aConverters
[i
].isOK())
109 bSomethingCapable
= true;
113 if (!bSomethingCapable
)
117 sal_Unicode cEnd
= c
;
118 printf(" if (c < 0x%x)\n", c
);
119 printf(" return %s;\n", aConverters
[nMostCapable
].getName());
122 bool bNothingCapable
= true;
123 for (size_t i
= 0; i
< std::size(aConverters
); ++i
)
125 aConverters
[i
].checkSupports(c
);
126 if (aConverters
[i
].isOK())
128 bNothingCapable
= false;
132 if (!bNothingCapable
)
140 printf(" if (c < 0x%x)\n", c
);
141 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
144 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */