jehanne/sys/src/lib/jehanne/port/utfrune.c

39 lines
851 B
C

/*
* This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
* part of the UCB release of Plan 9, including this file, may be copied,
* modified, propagated, or distributed except according to the terms contained
* in the LICENSE file.
*/
#include <u.h>
#include <libc.h>
char*
jehanne_utfrune(const char *s, Rune c)
{
int32_t c1;
Rune r;
int n;
if(c < Runesync) /* not part of utf sequence */
return jehanne_strchr(s, c);
for(;;) {
c1 = *(uint8_t*)s;
if(c1 < Runeself) { /* one byte rune */
if(c1 == 0)
return 0;
if(c1 == c)
return (char*)s;
s++;
continue;
}
n = jehanne_chartorune(&r, s);
if(r == c)
return (char*)s;
s += n;
}
}