Skip to content

Commit

Permalink
Iconv: Skip invalid output chars in iconv if requested
Browse files Browse the repository at this point in the history
If `skip` is selected we can use the `//IGNORE` suffix to ignore any
"character [that] cannot be represented in the target character set" in
iconv instead of doing so in the convert code causing (at least) multiple
invocations of `iconv`.
If the suffix is not supported (it is by libc and libiconv) fall back to
previous code.
  • Loading branch information
Flamefire committed Jan 14, 2025
1 parent 37bbbf4 commit 4977551
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/encoding/iconv_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ namespace boost { namespace locale { namespace conv { namespace impl {
public:
bool do_open(const char* to, const char* from, method_type how)
{
cvt_ = iconv_open(to, from);
how_ = how;
if(how == skip) {
std::string tmp_to(to);
tmp_to += "//IGNORE";
cvt_ = iconv_open(tmp_to.c_str(), from);
if(cvt_)
return true;
// Else try regular and handle invalids in convert
}
cvt_ = iconv_open(to, from);
return static_cast<bool>(cvt_);
}

Expand Down

0 comments on commit 4977551

Please sign in to comment.