You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Tim Bray <tb...@textuality.com> on 2000/02/02 00:28:41 UTC

Mini-Unicode module needed?

Hi - I have this great big honkin' Apache module (C, not perl) that I've
written to do some very specific things in regard to my startup.  Recently,
I had to make it do Unicode.  I looked around at iconv and ICU and some
combination of being-in-C++ and being-heavyweight and 
doing-stuff-I-didnt-need made them unattractive.

So now I have a bunch of useful little thingies in my module like

/*
 * gives you the next unicode character in the UTF-8 buffer as an int, 
 *  moves the pointer along
 */
int nextUnicodeCharFromUTF8(unsigned char * * inP)

/*
 * stuff a Unicode stored in an int into a buffer in UTF-8, return new
 *  buffer pointer
 */
unsigned char * storeUTF8At(int c, unsigned char * at)

/*
 * downcase a Unicode string the way perl would.  Careful, in principle,
 *  the output string could be longer than the input
 */
void downcaseUnicodeString(unsigned char * in, unsigned char * out)

/* is the Unicode character in c what perl would think of as \w? */
int isWordChar(int c)

Hm... maybe those should be wchar_t, not int, variables? 

The only technically interesting thing is that this is [no shit, Sherlock]
table-driven, and the tables are computed by parsing the modules in 
$PerlHome/lib/unicode/Is/* and $PerlHome/lib/unicode/In/*, which are
in turn generated by processing Unicode files directly, but this way
makes it *sure* that the C code will have the exact same idea of of
case and \w-ness as some particular version of perl.  This is done
by a moronic perl script that reads the Is/* and In/* and writes a 
complicated .h file.

This implementation makes no attempt to save space, so you burn 192K of
tables [and a few dozen bytes of code maybe].  Probably I'll be forced
to compact the tables because I think the performance hit will be 
tiny and 192K is a bit much to waste even these days.

Soo.... the question is [and maybe this isn't the right place to ask
it]: should I rip this stuff out and make a little wee mod_Unicode for
desperados who have to do C-level Apache programming?  Or is this
wasteful/duplicative/ill-thought-out and not really of benefit to
anyone.  -T.


Re: Mini-Unicode module needed?

Posted by Dirk-Willem van Gulik <di...@webweaving.org>.

Tim Bray wrote:

> Hi - I have this great big honkin' Apache module (C, not perl) that I've
> written to do some very specific things in regard to my startup.  Recently,
> I had to make it do Unicode.  I looked around at iconv and ICU and some
> combination of being-in-C++ and being-heavyweight and
> doing-stuff-I-didnt-need made them unattractive.

I found the same same thing; and used the C3 API to pre-generate *.h
tables to do utf7/8 <--> latin(1-8) conversion and approximation. (
without language param's; i.e no. u\: <-> eu | u conflict resulution
etc, etc.).

> Soo.... the question is [and maybe this isn't the right place to ask
> it]: should I rip this stuff out and make a little wee mod_Unicode for
> desperados who have to do C-level Apache programming?  Or is this
> wasteful/duplicative/ill-thought-out and not really of benefit to
> anyone.  -T.

IMHO, as I found myself carrying such code from project to project,
having a
good utf8/unicode + approx/mapping table to things such as latinX, shift-J,
big5 and koi8, such a (public) library is an asset. It should be made a 
library for easy use. And it should be small !

But if it grows as heavy as the c++ gorilla's currently in use.. then 
please don't !

Dw