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>
17 rtl_UnicodeToTextConverter m_aConverter
;
19 rtl_TextEncoding m_nEncoding
;
20 const char *m_pEncoding
;
21 Encoder(rtl_TextEncoding nEncoding
, const char *pEncoding
)
23 , m_nEncoding(nEncoding
)
24 , m_pEncoding(pEncoding
)
26 m_aConverter
= rtl_createUnicodeToTextConverter(m_nEncoding
);
30 rtl_destroyUnicodeToTextConverter(m_aConverter
);
32 void checkSupports(sal_Unicode c
)
34 sal_Char aTempArray
[8];
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;
52 const char* getName() const
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("#include <rtl/textenc.h>\n");
84 printf("#include <tools/tenccvt.hxx>\n");
85 printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
91 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
92 aConverters
[i
].reset();
94 int nMostCapable
= -1;
98 bool bSomethingCapable
= false;
99 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
101 if (aConverters
[i
].isOK())
102 aConverters
[i
].checkSupports(c
);
103 if (aConverters
[i
].isOK())
105 bSomethingCapable
= true;
109 if (!bSomethingCapable
)
113 sal_Unicode cEnd
= c
;
114 printf(" if (c < 0x%x)\n", c
);
115 printf(" return %s;\n", aConverters
[nMostCapable
].getName());
118 bool bNothingCapable
= true;
119 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
121 aConverters
[i
].checkSupports(c
);
122 if (aConverters
[i
].isOK())
124 bNothingCapable
= false;
128 if (!bNothingCapable
)
136 printf(" if (c < 0x%x)\n", c
);
137 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
140 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */