From: Tim Goya Date: Fri, 9 Nov 2007 22:09:09 +0000 (+0000) Subject: Use SDL_iconv functions for better portability X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8de58c8f39896f7f5e287d46544ddd045f527824;p=supertux.git Use SDL_iconv functions for better portability SVN-Revision: 5182 --- diff --git a/src/tinygettext/tinygettext.cpp b/src/tinygettext/tinygettext.cpp index 3da855a0b..d22ae2a6f 100644 --- a/src/tinygettext/tinygettext.cpp +++ b/src/tinygettext/tinygettext.cpp @@ -20,13 +20,14 @@ #include #include -#include #include #include #include #include #include +#include "SDL.h" + #include "tinygettext.hpp" #include "log.hpp" #include "physfs/physfs_stream.hpp" @@ -45,7 +46,20 @@ std::string convert(const std::string& text, if (from_charset == to_charset) return text; - iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str()); + char *in = new char[text.length() + 1]; + strcpy(in, text.c_str()); + char *out = SDL_iconv_string(to_charset.c_str(), from_charset.c_str(), in, text.length() + 1); + delete[] in; + if(out == 0) + { + log_warning << "Error: conversion from " << from_charset << " to " << to_charset << " failed" << std::endl; + return ""; + } + std::string ret(out); + SDL_free(out); + return ret; +#if 0 + iconv_t cd = SDL_iconv_open(to_charset.c_str(), from_charset.c_str()); size_t in_len = text.length(); size_t out_len = text.length()*3; // FIXME: cross fingers that this is enough @@ -59,7 +73,7 @@ std::string convert(const std::string& text, size_t out_len_temp = out_len; // iconv is counting down the bytes it has // written from this... - size_t retval = iconv(cd, &in, &in_len, &out, &out_len_temp); + size_t retval = SDL_iconv(cd, &in, &in_len, &out, &out_len_temp); out_len -= out_len_temp; // see above if (retval == (size_t) -1) { @@ -67,12 +81,13 @@ std::string convert(const std::string& text, log_warning << "Error: conversion from " << from_charset << " to " << to_charset << " went wrong: " << retval << std::endl; return ""; } - iconv_close(cd); + SDL_iconv_close(cd); std::string ret(out_orig, out_len); delete[] out_orig; delete[] in_orig; return ret; +#endif } bool has_suffix(const std::string& lhs, const std::string rhs)