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 | |
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.
-rw-r--r-- | gtk/Converter.h | 31 | ||||
-rw-r--r-- | gtk/PlatGTK.cxx | 16 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 8 |
3 files changed, 23 insertions, 32 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); } } }; diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 700e88164..74f095bc5 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -655,12 +655,12 @@ static std::string UTF8FromIconv(const Converter &conv, const char *s, int len) if (conv) { std::string utfForm(len*3+1, '\0'); char *pin = const_cast<char *>(s); - size_t inLeft = len; + gsize inLeft = len; char *putf = &utfForm[0]; char *pout = putf; - size_t outLeft = len*3+1; - size_t conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); - if (conversions != ((size_t)(-1))) { + gsize outLeft = len*3+1; + gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + if (conversions != sizeFailure) { *pout = '\0'; utfForm.resize(pout - putf); return utfForm; @@ -675,11 +675,11 @@ static size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t for (size_t lenMB=1; (lenMB<4) && (lenMB <= len); lenMB++) { char wcForm[2]; char *pin = const_cast<char *>(s); - size_t inLeft = lenMB; + gsize inLeft = lenMB; char *pout = wcForm; - size_t outLeft = 2; - size_t conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); - if (conversions != ((size_t)(-1))) { + gsize outLeft = 2; + gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + if (conversions != sizeFailure) { return lenMB; } } diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 14b861348..10514eece 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -926,15 +926,15 @@ static std::string ConvertText(const char *s, size_t len, const char *charSetDes std::string destForm; Converter conv(charSetDest, charSetSource, transliterations); if (conv) { - size_t outLeft = len*3+1; + gsize outLeft = len*3+1; destForm = std::string(outLeft, '\0'); // g_iconv does not actually write to its input argument so safe to cast away const char *pin = const_cast<char *>(s); - size_t inLeft = len; + gsize inLeft = len; char *putf = &destForm[0]; char *pout = putf; - size_t conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); - if (conversions == ((size_t)(-1))) { + gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + if (conversions == sizeFailure) { if (!silent) { if (len == 1) fprintf(stderr, "iconv %s->%s failed for %0x '%s'\n", |