diff options
Diffstat (limited to 'gtk/Converter.h')
| -rw-r--r-- | gtk/Converter.h | 31 | 
1 files changed, 21 insertions, 10 deletions
| diff --git a/gtk/Converter.h b/gtk/Converter.h index 7dc2e6875..d3038a2f2 100644 --- a/gtk/Converter.h +++ b/gtk/Converter.h @@ -23,6 +23,16 @@ size_t iconv_adaptor(size_t(*f_iconv)(ConverterHandle, T, size_t *, char **, siz   */  class Converter {  	ConverterHandle iconvh; +	void OpenHandle(const char *fullDestination, const char *charSetSource) { +#if GTK_MAJOR_VERSION >= 2 +		iconvh = g_iconv_open(fullDestination, charSetSource); +#else +		iconvh = iconv_open(fullDestination, charSetSource); +#endif +	} +	bool Succeeded() const { +		return iconvh != iconvhBad; +	}  public:  	Converter() {  		iconvh = iconvhBad; @@ -35,25 +45,26 @@ public:  		Close();  	}  	operator bool() const { -		return iconvh != iconvhBad; +		return Succeeded();  	}  	void Open(const char *charSetDestination, const char *charSetSource, bool transliterations=true) {  		Close();  		if (*charSetSource) { -			char fullDest[200]; -			strcpy(fullDest, charSetDestination); +			// Try allowing approximate transliterations  			if (transliterations) { +				char fullDest[200]; +				strcpy(fullDest, charSetDestination);  				strcat(fullDest, "//TRANSLIT"); +				OpenHandle(fullDest, charSetSource); +			} +			if (!Succeeded()) { +				// Transliterations failed so try basic name +				OpenHandle(charSetDestination, charSetSource);  			} -#if GTK_MAJOR_VERSION >= 2 -			iconvh = g_iconv_open(fullDest, charSetSource); -#else -			iconvh = iconv_open(fullDest, charSetSource); -#endif  		}  	}  	void Close() { -		if (iconvh != iconvhBad) { +		if (Succeeded()) {  #if GTK_MAJOR_VERSION >= 2  			g_iconv_close(iconvh);  #else @@ -63,7 +74,7 @@ public:  		}  	}  	size_t Convert(char** src, size_t *srcleft, char **dst, size_t *dstleft) const { -		if (iconvh == iconvhBad) { +		if (!Succeeded()) {  			return (size_t)(-1);  		} else {  #if GTK_MAJOR_VERSION >= 2 | 
