diff options
author | Neil Hodgson <unknown> | 2016-05-05 10:48:38 +1000 |
---|---|---|
committer | Neil Hodgson <unknown> | 2016-05-05 10:48:38 +1000 |
commit | 1c5cc9a5fc8a6bfb9b9791338c5c5a20b21288e8 (patch) | |
tree | b81725cb18083a8f5189e536e7f84ef1db12625f /gtk/Converter.h | |
parent | e3783223da84055c7ad9cc5bead37d2649166170 (diff) | |
download | scintilla-mirror-1c5cc9a5fc8a6bfb9b9791338c5c5a20b21288e8.tar.gz |
Remove template adaptor as only g_iconv is used now. Use glib's gsize type as it
matches g_iconv exactly. Make character set name buffer dynamically sized.
Diffstat (limited to 'gtk/Converter.h')
-rw-r--r-- | gtk/Converter.h | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/gtk/Converter.h b/gtk/Converter.h index be530341f..f17949d98 100644 --- a/gtk/Converter.h +++ b/gtk/Converter.h @@ -10,21 +10,13 @@ namespace Scintilla { #endif -typedef GIConv ConverterHandle; -const ConverterHandle iconvhBad = (ConverterHandle)(-1); -// Since various versions of iconv can not agree on whether the src argument -// is char ** or const char ** provide a templatised adaptor. -template<typename T> -size_t iconv_adaptor(size_t(*f_iconv)(ConverterHandle, T, size_t *, char **, size_t *), - ConverterHandle cd, char** src, size_t *srcleft, - char **dst, size_t *dstleft) { - return f_iconv(cd, (T)src, srcleft, dst, dstleft); -} +const GIConv iconvhBad = (GIConv)(-1); +const gsize sizeFailure = static_cast<gsize>(-1); /** - * Encapsulate iconv safely and avoid iconv_adaptor complexity in client code. + * Encapsulate g_iconv safely. */ class Converter { - ConverterHandle iconvh; + GIConv iconvh; void OpenHandle(const char *fullDestination, const char *charSetSource) { iconvh = g_iconv_open(fullDestination, charSetSource); } @@ -45,15 +37,14 @@ public: operator bool() const { return Succeeded(); } - void Open(const char *charSetDestination, const char *charSetSource, bool transliterations=true) { + void Open(const char *charSetDestination, const char *charSetSource, bool transliterations) { Close(); if (*charSetSource) { // Try allowing approximate transliterations if (transliterations) { - char fullDest[200]; - g_strlcpy(fullDest, charSetDestination, sizeof(fullDest)); - g_strlcat(fullDest, "//TRANSLIT", sizeof(fullDest)); - OpenHandle(fullDest, charSetSource); + std::string fullDest(charSetDestination); + fullDest.append("//TRANSLIT"); + OpenHandle(fullDest.c_str(), charSetSource); } if (!Succeeded()) { // Transliterations failed so try basic name @@ -67,11 +58,11 @@ public: iconvh = iconvhBad; } } - size_t Convert(char** src, size_t *srcleft, char **dst, size_t *dstleft) const { + gsize Convert(char** src, gsize *srcleft, char **dst, gsize *dstleft) const { if (!Succeeded()) { - return (size_t)(-1); + return sizeFailure; } else { - return iconv_adaptor(g_iconv, iconvh, src, srcleft, dst, dstleft); + return g_iconv(iconvh, src, srcleft, dst, dstleft); } } }; |