coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fold: add the --characters option


From: Collin Funk
Subject: fold: add the --characters option
Date: Wed, 20 Aug 2025 21:51:40 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

I noticed that Fedora and OpenSUSE (likely others) add a patch to
Coreutils for 'fold --characters'. Not sure if that option has been
discussed here.

Anyways, I wrote the following patch which is much simpler than the one
they use, in my opinion. The mbfile module from Gnulib provides a
similar interface to stdio's getc. When operating on ascii characters it
does not call mbrtoc32, etc.

Here is an example of the behavior using 뉐 which has a width of two
columns:

    $ for i in $(seq 10); do printf '\uB250' >> test.txt; done
    $ printf '\n' >> test.txt
    $ cat test.txt
    뉐뉐뉐뉐뉐뉐뉐뉐뉐뉐
    $ ./src/fold -w 5 test.txt 
    뉐뉐
    뉐뉐
    뉐뉐
    뉐뉐
    뉐뉐
    $ ./src/fold --characters -w 5 test.txt 
    뉐뉐뉐뉐뉐
    뉐뉐뉐뉐뉐

What do you think?

It would be nice to improve unicode support and this was an easy
start. Something like 'tr' is much more difficult.

Collin

Attachment: 0001-fold-add-the-characters-option.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]