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("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
89 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aConverters
); ++i
)
90 aConverters
[i
].reset();
92 int nMostCapable
= -1;
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;
107 if (!bSomethingCapable
)
111 sal_Unicode cEnd
= c
;
112 printf(" if (c < 0x%x)\n", c
);
113 printf(" return %s;\n", aConverters
[nMostCapable
].getName());
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;
126 if (!bNothingCapable
)
134 printf(" if (c < 0x%x)\n", c
);
135 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
138 printf(" return RTL_TEXTENCODING_DONTKNOW;\n");
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */