Adjust 'fall through' comments to be recognized by GCC
[geany-mirror.git] / scintilla / gtk / Converter.h
blobf17949d98e4240e7e3bb59ef75e5c31120ebd1f7
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.
6 #ifndef CONVERTER_H
7 #define CONVERTER_H
9 #ifdef SCI_NAMESPACE
10 namespace Scintilla {
11 #endif
13 const GIConv iconvhBad = (GIConv)(-1);
14 const gsize sizeFailure = static_cast<gsize>(-1);
15 /**
16 * Encapsulate g_iconv safely.
18 class Converter {
19 GIConv iconvh;
20 void OpenHandle(const char *fullDestination, const char *charSetSource) {
21 iconvh = g_iconv_open(fullDestination, charSetSource);
23 bool Succeeded() const {
24 return iconvh != iconvhBad;
26 public:
27 Converter() {
28 iconvh = iconvhBad;
30 Converter(const char *charSetDestination, const char *charSetSource, bool transliterations) {
31 iconvh = iconvhBad;
32 Open(charSetDestination, charSetSource, transliterations);
34 ~Converter() {
35 Close();
37 operator bool() const {
38 return Succeeded();
40 void Open(const char *charSetDestination, const char *charSetSource, bool transliterations) {
41 Close();
42 if (*charSetSource) {
43 // Try allowing approximate transliterations
44 if (transliterations) {
45 std::string fullDest(charSetDestination);
46 fullDest.append("//TRANSLIT");
47 OpenHandle(fullDest.c_str(), charSetSource);
49 if (!Succeeded()) {
50 // Transliterations failed so try basic name
51 OpenHandle(charSetDestination, charSetSource);
55 void Close() {
56 if (Succeeded()) {
57 g_iconv_close(iconvh);
58 iconvh = iconvhBad;
61 gsize Convert(char** src, gsize *srcleft, char **dst, gsize *dstleft) const {
62 if (!Succeeded()) {
63 return sizeFailure;
64 } else {
65 return g_iconv(iconvh, src, srcleft, dst, dstleft);
70 #ifdef SCI_NAMESPACE
72 #endif
74 #endif