X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftinygettext%2Ftinygettext.cpp;h=ffaaf710da3c97c1271039980d99abb2e8ccfb43;hb=5ee161985d711c1cbe18b51b6db0076e34ddf613;hp=3da855a0b274956ad4cb0ac4bd92135c74a226bd;hpb=506698edf3c8c72eefda00962b57eb49ff0ec03b;p=supertux.git diff --git a/src/tinygettext/tinygettext.cpp b/src/tinygettext/tinygettext.cpp index 3da855a0b..ffaaf710d 100644 --- a/src/tinygettext/tinygettext.cpp +++ b/src/tinygettext/tinygettext.cpp @@ -20,17 +20,17 @@ #include #include -#include #include #include #include #include #include +#include "SDL.h" + #include "tinygettext.hpp" #include "log.hpp" #include "physfs/physfs_stream.hpp" -#include "log.hpp" #include "findlocale.hpp" //#define TRANSLATION_DEBUG @@ -45,7 +45,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 +72,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 +80,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) @@ -209,7 +223,7 @@ DictionaryManager::parseLocaleAliases() char c = ' '; while(in.good() && !in.eof()) { - while(isspace(c) && !in.eof()) + while(isspace(static_cast(c)) && !in.eof()) in.get(c); if(c == '#') { // skip comments @@ -219,14 +233,14 @@ DictionaryManager::parseLocaleAliases() } std::string alias; - while(!isspace(c) && !in.eof()) { + while(!isspace(static_cast(c)) && !in.eof()) { alias += c; in.get(c); } - while(isspace(c) && !in.eof()) + while(isspace(static_cast(c)) && !in.eof()) in.get(c); std::string language; - while(!isspace(c) && !in.eof()) { + while(!isspace(static_cast(c)) && !in.eof()) { language += c; in.get(c); } @@ -694,6 +708,9 @@ public: { state = SKIP_COMMENT; } + else if (c == '\n') + { + } else { // Read a new token @@ -701,7 +718,7 @@ public: do { // Read keyword token.keyword += c; - } while((c = getchar(in)) != EOF && !isspace(c)); + } while((c = getchar(in)) != EOF && !isspace(static_cast(c))); in.unget(); state = READ_CONTENT; @@ -715,12 +732,13 @@ public: // Found start of content state = READ_CONTENT_IN_STRING; break; - } else if (isspace(c)) { + } else if (isspace(static_cast(c))) { // skip } else { // Read something that may be a keyword in.unget(); state = READ_KEYWORD; add_token(token); + token = Token(); break; } } @@ -759,6 +777,7 @@ public: } } add_token(token); + token = Token(); } };