Skip to content

Commit 98dafbf

Browse files
committed
Iconv: Skip invalid output chars in iconv if requested
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.
1 parent 3fe3dac commit 98dafbf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/encoding/iconv_converter.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ namespace boost { namespace locale { namespace conv { namespace impl {
2020
public:
2121
bool do_open(const char* to, const char* from, method_type how)
2222
{
23-
cvt_ = iconv_open(to, from);
2423
how_ = how;
24+
if(how == skip) {
25+
std::string tmp_to(to);
26+
tmp_to += "//IGNORE";
27+
cvt_ = iconv_open(tmp_to.c_str(), from);
28+
if(cvt_)
29+
return true;
30+
// Else try regular and handle invalids in convert
31+
}
32+
cvt_ = iconv_open(to, from);
2533
return static_cast<bool>(cvt_);
2634
}
2735

0 commit comments

Comments
 (0)