1 // Scintilla source code edit control
2 // Converter.h - Encapsulation of iconv
3 // Copyright 2004 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
13 const GIConv iconvhBad
= (GIConv
)(-1);
14 const gsize sizeFailure
= static_cast<gsize
>(-1);
16 * Encapsulate g_iconv safely.
20 void OpenHandle(const char *fullDestination
, const char *charSetSource
) {
21 iconvh
= g_iconv_open(fullDestination
, charSetSource
);
23 bool Succeeded() const {
24 return iconvh
!= iconvhBad
;
30 Converter(const char *charSetDestination
, const char *charSetSource
, bool transliterations
) {
32 Open(charSetDestination
, charSetSource
, transliterations
);
37 operator bool() const {
40 void Open(const char *charSetDestination
, const char *charSetSource
, bool transliterations
) {
43 // Try allowing approximate transliterations
44 if (transliterations
) {
45 std::string
fullDest(charSetDestination
);
46 fullDest
.append("//TRANSLIT");
47 OpenHandle(fullDest
.c_str(), charSetSource
);
50 // Transliterations failed so try basic name
51 OpenHandle(charSetDestination
, charSetSource
);
57 g_iconv_close(iconvh
);
61 gsize
Convert(char** src
, gsize
*srcleft
, char **dst
, gsize
*dstleft
) const {
65 return g_iconv(iconvh
, src
, srcleft
, dst
, dstleft
);