handle/throw on invalid encoding for ucnv_open

This commit is contained in:
Dane Springmeyer 2014-12-02 14:21:36 -05:00
parent 9d5e46a1f9
commit 946434002f
3 changed files with 14 additions and 5 deletions

View file

@ -43,7 +43,6 @@ public:
mapnik::value_unicode_string transcode(const char* data, std::int32_t length = -1) const;
~transcoder();
private:
bool ok_;
UConverter * conv_;
};
}

View file

@ -34,13 +34,15 @@
namespace mapnik {
transcoder::transcoder (std::string const& encoding)
: ok_(false),
conv_(0)
: conv_(0)
{
UErrorCode err = U_ZERO_ERROR;
conv_ = ucnv_open(encoding.c_str(),&err);
if (U_SUCCESS(err)) ok_ = true;
// TODO ??
if (!U_SUCCESS(err))
{
// NOT: conv_ should be null on error so no need to call ucnv_close
throw std::runtime_error(std::string("could not create converter for ") + encoding);
}
}
mapnik::value_unicode_string transcoder::transcode(const char* data, std::int32_t length) const

View file

@ -1,6 +1,7 @@
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#include <mapnik/projection.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/map.hpp>
#include <mapnik/save_map.hpp>
#include <mapnik/graphics.hpp>
@ -53,6 +54,13 @@ int main(int argc, char** argv)
BOOST_TEST(true);
}
try {
mapnik::transcoder tr("bogus encoding");
BOOST_TEST(false);
} catch (...) {
BOOST_TEST(true);
}
mapnik::Map map(256,256);
mapnik::rule r;
r.set_filter(mapnik::parse_expression("[foo]='bar'"));