|
| From: | Pádraig Brady |
| Subject: | Re: fold: move multi-byte character reading to a module |
| Date: | Mon, 29 Sep 2025 12:34:49 +0100 |
| User-agent: | Mozilla Thunderbird Beta |
On 29/09/2025 04:39, Collin Funk wrote:
This patch moves some logic from 'fold' into a local Gnulib module that
can be used by other programs.
The module is used in a similar manner to getc (). Here is a trivial
example of it's use:
#include "mbbuf.h"
mcel_t g;
while ((g = mbbuf_next_char (istream)).ch != MBBUF_EOF)
fwrite (mbbuf_prev_char (g), 1, g.len, stdout);
This module should make it pretty easy to port programs who use getc ()
and putc (). And it will make sure that invalid multi-byte characters
are treated consistently across programs.
Performance is the same as coreutils-9.8 since the logic isn't really
changed.
Thoughts?
Excellent idea. Given we've catered for various cases in fold(1), reusing that logic makes a lot of sense. mbbuf_get_char() + mbbuf_char_offset() may be preferable to mbbuf_next_char() + mbbuf_prev_char() ? I'd change "first character in the previously read character" to "first _byte_ in the previously read character". The module Depends should add: c99, mcel. This gl module uses "ioblksize.h" which by right should thus made into a gl module so that gl modules are self contained / easy to move to gnulib. We can do that after anyway. There are a couple of minor `make syntax-check` issues. I'd change the license to the same as mcel (LGPLv2+) in case it's ever moved to gnulib. thanks! Padraig
| [Prev in Thread] | Current Thread | [Next in Thread] |