Changeset View
Changeset View
Standalone View
Standalone View
source/third_party/tinygettext/include/tinygettext/iconv.hpp
Show All 16 Lines | |||||
// misrepresented as being the original software. | // misrepresented as being the original software. | ||||
// 3. This notice may not be removed or altered from any source distribution. | // 3. This notice may not be removed or altered from any source distribution. | ||||
#ifndef HEADER_TINYGETTEXT_ICONV_HPP | #ifndef HEADER_TINYGETTEXT_ICONV_HPP | ||||
#define HEADER_TINYGETTEXT_ICONV_HPP | #define HEADER_TINYGETTEXT_ICONV_HPP | ||||
#include <string> | #include <string> | ||||
#ifdef HAVE_SDL | #ifdef TINYGETTEXT_WITH_SDL | ||||
# include "SDL.h" | # include "SDL.h" | ||||
# define tinygettext_ICONV_CONST const | |||||
# define tinygettext_iconv_t SDL_iconv_t | |||||
# define tinygettext_iconv SDL_iconv | |||||
# define tinygettext_iconv_open SDL_iconv_open | |||||
# define tinygettext_iconv_close SDL_iconv_close | |||||
#else | #else | ||||
# include <iconv.h> | # include <iconv.h> | ||||
#endif | |||||
namespace tinygettext { | |||||
namespace detail { | |||||
struct ConstPtrHack { | |||||
const char** ptr; | |||||
inline ConstPtrHack(char** ptr_) : ptr(const_cast<const char**>(ptr_)) {} | |||||
inline ConstPtrHack(const char** ptr_) : ptr(ptr_) {} | |||||
inline operator const char**() const { return ptr; } | |||||
inline operator char**() const { return const_cast<char**>(ptr); } | |||||
}; | |||||
} // namespace detail | |||||
#ifdef TINYGETTEXT_WITH_SDL | |||||
using iconv_t = ::SDL_iconv_t; | |||||
#else | |||||
using iconv_t = ::iconv_t; | |||||
#endif | |||||
# ifdef HAVE_ICONV_CONST | inline iconv_t iconv_open(const char* tocode, const char* fromcode) | ||||
# define tinygettext_ICONV_CONST ICONV_CONST | { | ||||
#ifdef TINYGETTEXT_WITH_SDL | |||||
return SDL_iconv_open(tocode, fromcode); | |||||
# else | #else | ||||
# define tinygettext_ICONV_CONST | return ::iconv_open(tocode, fromcode); | ||||
# endif | #endif | ||||
} | |||||
# define tinygettext_iconv_t iconv_t | inline size_t iconv(iconv_t cd, | ||||
# define tinygettext_iconv iconv | const char** inbuf, size_t* inbytesleft, | ||||
# define tinygettext_iconv_open iconv_open | char** outbuf, size_t* outbytesleft) | ||||
# define tinygettext_iconv_close iconv_close | { | ||||
#ifdef TINYGETTEXT_WITH_SDL | |||||
return SDL_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); | |||||
#else | |||||
return ::iconv(cd, detail::ConstPtrHack(inbuf), inbytesleft, outbuf, outbytesleft); | |||||
#endif | #endif | ||||
} | |||||
namespace tinygettext { | inline int iconv_close(iconv_t cd) | ||||
{ | |||||
#ifdef TINYGETTEXT_WITH_SDL | |||||
return SDL_iconv_close(cd); | |||||
#else | |||||
return ::iconv_close(cd); | |||||
#endif | |||||
} | |||||
class IConv | class IConv | ||||
{ | { | ||||
private: | private: | ||||
std::string to_charset; | std::string to_charset; | ||||
std::string from_charset; | std::string from_charset; | ||||
tinygettext_iconv_t cd; | iconv_t cd; | ||||
public: | public: | ||||
IConv(); | IConv(); | ||||
IConv(const std::string& fromcode, const std::string& tocode); | IConv(const std::string& fromcode, const std::string& tocode); | ||||
~IConv(); | ~IConv(); | ||||
void set_charsets(const std::string& fromcode, const std::string& tocode); | void set_charsets(const std::string& fromcode, const std::string& tocode); | ||||
std::string convert(const std::string& text); | std::string convert(const std::string& text); | ||||
Show All 11 Lines |
Wildfire Games · Phabricator