On Mon, 25 Feb 2002 20:52:38 +0100 (CET)
Bruno Haible <[EMAIL PROTECTED]> wrote:
> > /*
> >  * Returns a pointer to the character at off withing the multi-byte string
>                                         ^^^^^^
> Emphasize: at _screen_position_ off.

Actually I think I really do want characters:

> >  * src not examining more than sn bytes.
> >  */
> > char *
> > mbsnoff(char *src, int off, size_t sn)
> > {
> >     unsigned long ucs;
> >     int w;  
> >     size_t n;
> >     mbstate_t ps;
> > 
> >     ucs = 1;
> >     memset(&ps, 0, sizeof(ps));
> > 
> >     if (sn > INT_MAX) {
> >         sn = INT_MAX;
> >     }
> >     if (off < 0) {
> >         off = INT_MAX;
> >     }

        while (sn > 0 && (n = mbrtowc(&ucs, src, sn, &ps)) != (size_t)-2) {
            if (n == (size_t)-1) {
                return NULL;
            }
            if ((w = wcwidth(ucs)) == -1) {
                w = 1;  
            }       
            if (w > off) {
                break;  
            }       
            off -= w;

> >         sn -= n;
> >         src += n;
> >     }
> > 
> >     return src;
> > }

Thanks,
Mike

-- 
May The Source be with you.
--
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/linux-utf8/

Reply via email to