"Fossies" - the Fresh Open Source Software Archive

Member "geany-1.36/scintilla/gtk/Converter.h" (28 Sep 2019, 1792 Bytes) of package /linux/misc/geany-1.36.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Converter.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.35_vs_1.36.

    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.
    5 
    6 #ifndef CONVERTER_H
    7 #define CONVERTER_H
    8 
    9 namespace Scintilla {
   10 
   11 const GIConv iconvhBad = (GIConv)(-1);
   12 const gsize sizeFailure = static_cast<gsize>(-1);
   13 /**
   14  * Encapsulate g_iconv safely.
   15  */
   16 class Converter {
   17     GIConv iconvh;
   18     void OpenHandle(const char *fullDestination, const char *charSetSource) noexcept {
   19         iconvh = g_iconv_open(fullDestination, charSetSource);
   20     }
   21     bool Succeeded() const noexcept {
   22         return iconvh != iconvhBad;
   23     }
   24 public:
   25     Converter() noexcept {
   26         iconvh = iconvhBad;
   27     }
   28     Converter(const char *charSetDestination, const char *charSetSource, bool transliterations) {
   29         iconvh = iconvhBad;
   30         Open(charSetDestination, charSetSource, transliterations);
   31     }
   32     ~Converter() {
   33         Close();
   34     }
   35     operator bool() const noexcept {
   36         return Succeeded();
   37     }
   38     void Open(const char *charSetDestination, const char *charSetSource, bool transliterations) {
   39         Close();
   40         if (*charSetSource) {
   41             // Try allowing approximate transliterations
   42             if (transliterations) {
   43                 std::string fullDest(charSetDestination);
   44                 fullDest.append("//TRANSLIT");
   45                 OpenHandle(fullDest.c_str(), charSetSource);
   46             }
   47             if (!Succeeded()) {
   48                 // Transliterations failed so try basic name
   49                 OpenHandle(charSetDestination, charSetSource);
   50             }
   51         }
   52     }
   53     void Close() noexcept {
   54         if (Succeeded()) {
   55             g_iconv_close(iconvh);
   56             iconvh = iconvhBad;
   57         }
   58     }
   59     gsize Convert(char **src, gsize *srcleft, char **dst, gsize *dstleft) const noexcept {
   60         if (!Succeeded()) {
   61             return sizeFailure;
   62         } else {
   63             return g_iconv(iconvh, src, srcleft, dst, dstleft);
   64         }
   65     }
   66 };
   67 
   68 }
   69 
   70 #endif