Blame


1 b2cfc4e2 2003-09-30 devnull /*
2 b2cfc4e2 2003-09-30 devnull * The authors of this software are Rob Pike and Ken Thompson.
3 b2cfc4e2 2003-09-30 devnull * Copyright (c) 2002 by Lucent Technologies.
4 b2cfc4e2 2003-09-30 devnull * Permission to use, copy, modify, and distribute this software for any
5 b2cfc4e2 2003-09-30 devnull * purpose without fee is hereby granted, provided that this entire notice
6 b2cfc4e2 2003-09-30 devnull * is included in all copies of any software which is or includes a copy
7 b2cfc4e2 2003-09-30 devnull * or modification of this software and in all copies of the supporting
8 b2cfc4e2 2003-09-30 devnull * documentation for such software.
9 b2cfc4e2 2003-09-30 devnull * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10 b2cfc4e2 2003-09-30 devnull * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11 b2cfc4e2 2003-09-30 devnull * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12 b2cfc4e2 2003-09-30 devnull * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
13 b2cfc4e2 2003-09-30 devnull */
14 b2cfc4e2 2003-09-30 devnull #include <stdarg.h>
15 b2cfc4e2 2003-09-30 devnull #include <string.h>
16 b2cfc4e2 2003-09-30 devnull #include "utf.h"
17 b2cfc4e2 2003-09-30 devnull #include "utfdef.h"
18 b2cfc4e2 2003-09-30 devnull
19 b2cfc4e2 2003-09-30 devnull
20 b2cfc4e2 2003-09-30 devnull /*
21 b2cfc4e2 2003-09-30 devnull * Return pointer to first occurrence of s2 in s1,
22 b2cfc4e2 2003-09-30 devnull * 0 if none
23 b2cfc4e2 2003-09-30 devnull */
24 b2cfc4e2 2003-09-30 devnull char*
25 b2cfc4e2 2003-09-30 devnull utfutf(char *s1, char *s2)
26 b2cfc4e2 2003-09-30 devnull {
27 b2cfc4e2 2003-09-30 devnull char *p;
28 b2cfc4e2 2003-09-30 devnull long f, n1, n2;
29 b2cfc4e2 2003-09-30 devnull Rune r;
30 b2cfc4e2 2003-09-30 devnull
31 b2cfc4e2 2003-09-30 devnull n1 = chartorune(&r, s2);
32 b2cfc4e2 2003-09-30 devnull f = r;
33 b2cfc4e2 2003-09-30 devnull if(f <= Runesync) /* represents self */
34 b2cfc4e2 2003-09-30 devnull return strstr(s1, s2);
35 b2cfc4e2 2003-09-30 devnull
36 b2cfc4e2 2003-09-30 devnull n2 = strlen(s2);
37 b2cfc4e2 2003-09-30 devnull for(p=s1; p=utfrune(p, f); p+=n1)
38 b2cfc4e2 2003-09-30 devnull if(strncmp(p, s2, n2) == 0)
39 b2cfc4e2 2003-09-30 devnull return p;
40 b2cfc4e2 2003-09-30 devnull return 0;
41 b2cfc4e2 2003-09-30 devnull }