Skip to content

Commit

Permalink
Merge pull request #32 from SLiV9/master
Browse files Browse the repository at this point in the history
Disambiguate iconv calls to avoid compilation issues on BSD.
  • Loading branch information
Grumbel committed Dec 11, 2020
2 parents 3c7c18f + 48de735 commit 51d1adc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/iconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ IConv::IConv(const std::string& from_charset_, const std::string& to_charset_)
IConv::~IConv()
{
if (cd)
iconv_close(cd);
tinygettext::iconv_close(cd);
}

void
IConv::set_charsets(const std::string& from_charset_, const std::string& to_charset_)
{
if (cd)
iconv_close(cd);
tinygettext::iconv_close(cd);

from_charset = from_charset_;
to_charset = to_charset_;
Expand All @@ -71,7 +71,7 @@ IConv::set_charsets(const std::string& from_charset_, const std::string& to_char
}
else
{
cd = iconv_open(to_charset.c_str(), from_charset.c_str());
cd = tinygettext::iconv_open(to_charset.c_str(), from_charset.c_str());
if (cd == reinterpret_cast<iconv_t>(-1))
{
if(errno == EINVAL)
Expand Down Expand Up @@ -111,12 +111,12 @@ IConv::convert(const std::string& text)
char* outbuf = &result[0];

// Try to convert the text.
size_t ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
size_t ret = tinygettext::iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (ret == static_cast<size_t>(-1))
{
if (errno == EILSEQ || errno == EINVAL)
{ // invalid multibyte sequence
iconv(cd, nullptr, nullptr, nullptr, nullptr); // reset state
tinygettext::iconv(cd, nullptr, nullptr, nullptr, nullptr); // reset state

// FIXME: Could try to skip the invalid byte and continue
log_error << "error: tinygettext:iconv: invalid multibyte sequence in: \"" << text << "\"" << std::endl;
Expand Down

0 comments on commit 51d1adc

Please sign in to comment.