[dev] [libutf] Proposal for additional rune utility functions

From: FRIGN <dev_AT_frign.de>
Date: Tue, 10 Feb 2015 19:20:45 +0100

Good evening fellow hackers,

working with sbase, we've decided a while ago to include libutf in the
repo and base all tools' UTF-8-support on it instead of the insane
wchar.h-interface.
Now that almost all tools have UTF-8-support, we, along the way,
implemented a number of utility functions which seemed necessary in
some cases and I'm now proposing to add these functions back to libutf.
The functions in question are:

1) chartorunearr(const char *str, Rune **r)[0]

Read in str and convert it to a null-terminated Rune-array. The
function takes care of proper memory allocation with exactly the right
amount of space needed.
This function was not added to the original libutf in Plan 9 because

"We have no routines for manipulating null-terminated arrays of Runes.
Although they should probably exist for completeness, we have found no
need for them, for the same reason that %S and L"..." are rarely
used."[1]
Now, having worked on tr(1) myself, I needed a function like this to
simplify the parser.
In many cases you don't need a such a function, but tr(1) is an
example where you do.

2) readrune(FILE *fp, Rune *r)[2]
   writerune(FILE *fp, Rune *r)[3]

You may have noticed that the prototypes here are shorter than the ones
in the given links.
Of course, a library function would not call eprintf(). It would
return -1 on error, 0 on EOF and > 0 the number of bytes read.
readrune and writerune operate on single runes only and have proven
to be very handy in many sbase tools.
In case this proposal here is generally accepted, the import of the
functions would happen just this way.

What is left to discuss is where to put these functions. I would propose
to place chartorunearr into rune.c, where already chartorune() and
others reside.
I would place readrune() and writerune() into a new file called
runeio.c.
The name doesn't really matter, because on the outside, only the utf.h-
header will be exported.

Let me know what you think.

Cheers

FRIGN

[0]: http://git.2f30.org/sbase/tree/libutf/chartorunearr.c
[1]: http://plan9.bell-labs.com/sys/doc/utf.html
[2]: http://git.2f30.org/sbase/tree/libutf/readrune.c
[3]: http://git.2f30.org/sbase/tree/libutf/writerune.c

-- 
FRIGN <dev_AT_frign.de>
Received on Tue Feb 10 2015 - 19:20:45 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 10 2015 - 19:24:07 CET