[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Applying outstanding patches [bug-grep]
From: |
Claudio Fontana |
Subject: |
Re: Applying outstanding patches [bug-grep] |
Date: |
Tue, 19 Apr 2005 08:33:11 +0200 (CEST) |
Hello,
--- Tim Waugh <address@hidden> wrote:
> On Thu, Apr 14, 2005 at 06:47:50PM +0100, Julian
> Foad wrote:
>
> > > I seem to remember that some of
> > >them are tweaked in various small ways.
> >
> > Eww. That's a recipe for breakage later.
>
> I might be wrong about it -- I really don't remember
> actually.
They are identical.
Here is an example helper function to remove that dup:
static off_t
mb_convert_offset (char* beg, off_t *offset) {
off_t bytes_left; /* return value 1 */
off_t converted_offset; /* return value 2 */
mbstate_t mbs;
memset (&mbs, '\0', sizeof (mbstate_t));
bytes_left = *offset;
converted_offset = 0;
while (bytes_left)
{
size_t mlen = mbrlen (beg + converted_offset,
bytes_left, &mbs);
if (mlen == (size_t) -1 || mlen == 0)
{
/* Incomplete character: treat as
single-byte. */
memset (&mbs, '\0', sizeof (mbstate_t));
converted_offset++; bytes_left--;
continue;
}
else if (mlen == (size_t) -2)
/* Offset points inside multibyte character:
* no good. */
break;
converted_offset += mlen;
bytes_left -= mlen;
}
*offset = converted_offset;
return bytes_left;
}
Then we can call it like this:
#ifdef MBS_SUPPORT
if (MB_CUR_MAX > 1 && !using_utf8)
bytes_left = mb_convert_offset (beg,
&offset);
#endif
beg += offset;
Claudio
---------------------------------------------------------------
Claudio Fontana - contacts
web: cmdftp.sourceforge.net/cfontana/
general purpose: sick_soul a yahoo d it
free sw development: sick_soul a users d sourceforge d net
___________________________________
Nuovo Yahoo! Messenger: E' molto più divertente: Audibles, Avatar, Webcam,
Giochi, Rubrica
Scaricalo ora!
http://it.messenger.yahoo.it
- Re: Applying outstanding patches [bug-grep], (continued)
- Re: Applying outstanding patches [bug-grep], Julian Foad, 2005/04/26
- Re: Applying outstanding patches [bug-grep], Tim Waugh, 2005/04/26
- Re: Applying outstanding patches [bug-grep], Tim Waugh, 2005/04/28
- Re: Applying outstanding patches [bug-grep], Julian Foad, 2005/04/28
- Re: Applying outstanding patches [bug-grep], Tim Waugh, 2005/04/28
- Re: Applying outstanding patches [bug-grep], Julian Foad, 2005/04/28
- Re: Applying outstanding patches [bug-grep], Charles Levert, 2005/04/28
- [bug-grep] Testing for UTF-8 bugs [was: Applying outstanding patches], Julian Foad, 2005/04/28
- Re: Testing for UTF-8 bugs [was: Applying outstanding patches] [bug-grep], Charles Levert, 2005/04/29
Re: Applying outstanding patches [bug-grep], Julian Foad, 2005/04/14
Re: Applying outstanding patches [bug-grep],
Claudio Fontana <=