Blame


1 91c13e54 2004-02-29 devnull /*
2 91c13e54 2004-02-29 devnull * The authors of this software are Rob Pike and Ken Thompson.
3 91c13e54 2004-02-29 devnull * Copyright (c) 2002 by Lucent Technologies.
4 91c13e54 2004-02-29 devnull * Permission to use, copy, modify, and distribute this software for any
5 91c13e54 2004-02-29 devnull * purpose without fee is hereby granted, provided that this entire notice
6 91c13e54 2004-02-29 devnull * is included in all copies of any software which is or includes a copy
7 91c13e54 2004-02-29 devnull * or modification of this software and in all copies of the supporting
8 91c13e54 2004-02-29 devnull * documentation for such software.
9 91c13e54 2004-02-29 devnull * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10 37488654 2004-12-29 devnull * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE
11 37488654 2004-12-29 devnull * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12 91c13e54 2004-02-29 devnull * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
13 91c13e54 2004-02-29 devnull */
14 91c13e54 2004-02-29 devnull #include <stdarg.h>
15 91c13e54 2004-02-29 devnull #include <string.h>
16 e5aa96ac 2004-12-26 devnull #include "plan9.h"
17 91c13e54 2004-02-29 devnull #include "utf.h"
18 91c13e54 2004-02-29 devnull
19 91c13e54 2004-02-29 devnull char*
20 91c13e54 2004-02-29 devnull utfrrune(char *s, long c)
21 91c13e54 2004-02-29 devnull {
22 91c13e54 2004-02-29 devnull long c1;
23 91c13e54 2004-02-29 devnull Rune r;
24 91c13e54 2004-02-29 devnull char *s1;
25 91c13e54 2004-02-29 devnull
26 91c13e54 2004-02-29 devnull if(c < Runesync) /* not part of utf sequence */
27 91c13e54 2004-02-29 devnull return strrchr(s, c);
28 91c13e54 2004-02-29 devnull
29 91c13e54 2004-02-29 devnull s1 = 0;
30 91c13e54 2004-02-29 devnull for(;;) {
31 91c13e54 2004-02-29 devnull c1 = *(uchar*)s;
32 91c13e54 2004-02-29 devnull if(c1 < Runeself) { /* one byte rune */
33 91c13e54 2004-02-29 devnull if(c1 == 0)
34 91c13e54 2004-02-29 devnull return s1;
35 91c13e54 2004-02-29 devnull if(c1 == c)
36 91c13e54 2004-02-29 devnull s1 = s;
37 91c13e54 2004-02-29 devnull s++;
38 91c13e54 2004-02-29 devnull continue;
39 91c13e54 2004-02-29 devnull }
40 91c13e54 2004-02-29 devnull c1 = chartorune(&r, s);
41 91c13e54 2004-02-29 devnull if(r == c)
42 91c13e54 2004-02-29 devnull s1 = s;
43 91c13e54 2004-02-29 devnull s += c1;
44 91c13e54 2004-02-29 devnull }
45 91c13e54 2004-02-29 devnull }