[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnu-libiconv] Libiconv iconv_string(...) cannot ignore incorrec
From: |
Bruno Haible |
Subject: |
Re: [bug-gnu-libiconv] Libiconv iconv_string(...) cannot ignore incorrect parts |
Date: |
Sun, 02 Apr 2023 16:27:16 +0200 |
Hi,
> I would like to provide some suggestions regarding my usage of the function
> iconv_string in programming. It has come to my attention that this function
> is unable to handle certain parts of a multi-byte string that contains
> errors. Oftentimes, there may be a segment of garbled characters within a
> string that requires ignore, causing iconv_string to be unable to handle the
> correct parts of the string.
>
> To address this issue, my suggestion is to modify the function to include an
> ignore errors feature. Specifically, I propose the following changes:
>
> ```
> /*
> If the boolean parameter "strict" is set to 1, input errors will be handled
> in a strict manner. If an error is encountered, encoding will stop
> immediately and return an error code.
> If the boolean parameter "strict" is set to 0, input errors will be handled
> in a relaxed manner. If an error is encountered, it will be skipped over and
> the return value will always be 0.
> */
> int iconv_string (const char* tocode, const char* fromcode,
> const char* start, const char* end,
> char** resultp, size_t* lengthp,
> bool strict);
> ```
>
> To avoid compilation errors for older programs that use iconv_string, I
> suggest make a new function "iconv_string_extend". These changes would not
> only address the issue that I have encountered, but also enhance the
> compatibility and expandability of the program.
> Like this:
> ```
> int iconv_string (const char* tocode, const char* fromcode,
> const char* start, const char* end,
> char** resultp, size_t* lengthp);
> int iconv_string_extend (const char* tocode, const char* fromcode,
> const char* start, const char* end,
> char** resultp, size_t* lengthp,
> bool strict);
> ```
> That is all, thank you.
What you write is reasonable.
But iconv_string is not part of GNU libiconv; it is only an example.
For this reason:
- There would be no need for backward compatibility.
- An example should strive for a compromise between real-world usability
and simplicity.
Therefore I don't think it's good to make this example function more
complicated.
Anyway, did you notice that you can have target encoding related errors
ignored by appending //IGNORE to the target encoding name? See
man/iconv_open.3.html.
Bruno