Article View: news.software.nntp
Article #44814Re: [NNTP Draft] 5. The WILDMAT format
From: Kai Henningsen
Date: Sun, 05 Mar 2000 00:00
Date: Sun, 05 Mar 2000 00:00
64 lines
3130 bytes
3130 bytes
rra@stanford.edu (Russ Allbery) wrote on 27.02.00 in <yld7pjxd6h.fsf@windlord.stanford.edu>:
> Andrew Gierth <andrew@erlenstar.demon.co.uk> writes:
>
> > I have a trial implementation of wildmat for UTF-8 strings; implementing
> > the character classes was not so bad (but I haven't tested it
> > extensively yet, so I may be premature in saying that :-)
>
> > Wildmat ranges are only single-character metacharacters which makes it
> > simple. The implementation is exactly the same as before, one simply
> > uses 32-bit variables rather than 8-bit ones (and UCS-4 only needs 31
> > bits, so signed 32-bit is ok) and converts UTF-8 characters into UCS-4
> > as they are read.
>
> How hard is the conversion to UCS-4?
Should be easy as long as you don't try to check for legal UTF-8 at the
same time.
Very much not optimized:
int ucs4;
char *seq, len;
if (*seq <= 0x7f) { ucs4 = *seq++; len = 0; }
else if (*seq <= 0xbf) { ucs4 = 0xfffd; len = 0; } // error case
else if (*seq <= 0xdf) { ucs4 = *seq & 0x1f; len = 1; }
else if (*seq <= 0xef) { ucs4 = *seq & 0x0f; len = 2; }
else if (*seq <= 0xf7) { ucs4 = *seq & 0x07; len = 3; }
// following cases are outside any range that will ever be allocated
// officially
else if (*seq <= 0xfb) { ucs4 = *seq & 0x03; len = 4; }
else if (*seq <= 0xfd) { ucs4 = *seq & 0x01; len = 5; }
else { ucs4 = 0xfffd; len = 0; } // error case
while (len--) {
// 0x80 <= *seq <= 0xbf
ucs4 <<= 6;
ucs4 |= (*seq++ & 0x3f);
}
That's it.
Or, to put it another way,
7 bit 0xxx xxxx
11 bit 110x xxxx 10xx xxxx
16 bit 1110 xxxx 10xx xxxx 10xx xxxx
21 bit 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
26 bit 1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx
31 bit 1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx
where the officially-allocatable range is 0x0000 0000 to 0x0010 ffff
(slightly over 20 bit). And 0x0000 fffd is the error char.
As for additional error checking, the rule is you must use the shortest
possible UTF8 sequence, so (say) 0xc0 0x80 is not legal for 0x00.
Kai
--
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
- Russ Allbery (rra@stanford.edu)
Technical Details
Message-ID:
<7$I4QDd1w-B@khms.westfalen.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<87snyfd367.fsf@erlenstar.demon.co.uk> <ylaekn2l33.fsf@windlord.stanford.edu> <87bt5385y2.fsf@erlenstar.demon.co.uk> <yld7pjxd6h.fsf@windlord.stanford.edu>Show Full Headers
Complete Article Headers
Message-ID: <7$I4QDd1w-B@khms.westfalen.de> Subject: Re: [NNTP Draft] 5. The WILDMAT format Date: Sun, 05 Mar 2000 00:00:00 +0000 From: kaih=7$I4QDd1w-B@khms.westfalen.de (Kai Henningsen) References: <87snyfd367.fsf@erlenstar.demon.co.uk> <ylaekn2l33.fsf@windlord.stanford.edu> <87bt5385y2.fsf@erlenstar.demon.co.uk> <yld7pjxd6h.fsf@windlord.stanford.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 593268468 X-Fix-Your-Modem: +++ATS2=255&WO1 Comment: Unsolicited commercial mail will incur an US$100 handling fee per received mail. Organization: Organisation? Me?! Are you kidding? X-No-Junk-Mail: I do not want to get *any* junk mail. Newsgroups: news.software.nntp