From: arisawa@ar.aichi-u.ac.jp
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] tcs bug
Date: Wed, 31 Aug 2005 19:48:22 +0900 [thread overview]
Message-ID: <D5198C91-A93E-4DD6-AB77-ACB8811A9250@ar.aichi-u.ac.jp> (raw)
In-Reply-To: <7359f0490508310217c214f1f@mail.gmail.com>
> one problem with this fix is that it assumes valid utf-8 input.
> you're better off using fullrune.
>
more simple and robust solution
that follows forsyth's suggestion
/* read until utf boundary */
int
readu(int fd, char *buf, int n)
{
static char b[3];
static int nb;
int m;
char *s, *e;
if(nb)
memcpy(buf, b, nb);
m = read(fd, buf + nb, n - nb);
/*
01. x in [00000000.0bbbbbbb] → 0bbbbbbb
10. x in [00000bbb.bbbbbbbb] → 110bbbbb, 10bbbbbb
11. x in [bbbbbbbb.bbbbbbbb] → 1110bbbb, 10bbbbbb,
10bbbbbb
*/
e = buf + m + nb;
for(s = e - 2; s < e; s++){
if((*s & 0xc0) == 0x80)
continue;
if((*s & 0xc0) == 0xc0)
break;
}
/* we have e - s bytes in s */
nb = e - s;
memcpy(b, s, nb);
return s - buf;
}
Kenji Arisawa
next prev parent reply other threads:[~2005-08-31 10:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-31 6:07 arisawa
2005-08-31 9:11 ` arisawa
2005-08-31 9:17 ` Rob Pike
2005-08-31 10:48 ` arisawa [this message]
2005-08-31 11:22 ` arisawa
-- strict thread matches above, loose matches on Subject: below --
2005-09-01 0:36 quanstro
2005-08-31 10:51 quanstro
2005-08-31 21:36 ` Russ Cox
2005-08-29 23:23 [9fans] some Plan9 related ideas Bhanu Nagendra Pisupati
2005-08-30 17:07 ` [9fans] " Dave Eckhardt
2005-08-30 17:33 ` Francisco Ballesteros
2005-08-30 17:46 ` Russ Cox
2005-08-31 5:54 ` [9fans] tcs bug arisawa
2005-08-31 5:57 ` Rob Pike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D5198C91-A93E-4DD6-AB77-ACB8811A9250@ar.aichi-u.ac.jp \
--to=arisawa@ar.aichi-u.ac.jp \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).