restored iconv support

This commit is contained in:
Artem Pavlenko 2007-08-29 15:21:32 +00:00
parent 388eb1761f
commit edb4150b33

View file

@ -163,44 +163,23 @@ namespace mapnik {
public: public:
explicit transcoder (std::string const& encoding) explicit transcoder (std::string const& encoding)
{ {
//desc_ = iconv_open("UCS-2",encoding.c_str()); #ifdef MAPNIK_DEBUG
std::cerr << "ENCODING = " << encoding << "\n";
#endif
desc_ = iconv_open("UTF-8",encoding.c_str());
} }
std::wstring transcode(std::string const& input) const std::wstring transcode(std::string const& input) const
{ {
//return to_unicode(input); if (desc_ == iconv_t(-1)) return to_unicode(input);
return to_unicode(input);
/* std::string buf(input.size() /* * sizeof(wchar_t)*/,0);
std::string buf(input.size() * 2,0);
size_t inleft = input.size(); size_t inleft = input.size();
const char * in = input.data(); const char * in = input.data();
size_t outleft = buf.size(); size_t outleft = buf.size();
char * out = const_cast<char*>(buf.data()); char * out = const_cast<char*>(buf.data());
iconv(desc_,&in,&inleft,&out,&outleft); iconv(desc_,&in,&inleft,&out,&outleft);
std::wstring unicode = to_unicode(buf);
std::string::const_iterator itr = buf.begin();
std::string::const_iterator end = buf.end();
wchar_t wch = 0;
bool state = false;
std::wstring unicode;
size_t num_char = buf.size() - outleft;
for ( ; itr != end; ++itr)
{
if (!state)
{
wch = (*itr & 0xff);
state = true;
}
else
{
wch |= *itr << 8 ;
unicode.push_back(wchar_t(wch));
state = false;
}
if (!num_char--) break;
}
#ifdef USE_FRIBIDI #ifdef USE_FRIBIDI
if (unicode.length() > 0) if (unicode.length() > 0)
{ {
@ -210,14 +189,13 @@ namespace mapnik {
} }
#endif #endif
return unicode; return unicode;
*/
} }
~transcoder() ~transcoder()
{ {
//iconv_close(desc_); if (desc_ != iconv_t(-1)) iconv_close(desc_);
} }
private: private:
iconv_t desc_; iconv_t desc_;
}; };