chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / string.c
1 /*
2  * Copyright (C) 2008 Kim Woelders
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies of the Software, its documentation and marketing & publicity
13  * materials, and acknowledgment shall be given in the documentation, materials
14  * and software packages that this Software was used.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #include "util.h"
24 #include <ctype.h>
25
26 #ifndef HAVE_STRCASECMP
27 int
28 Estrcasecmp(const char *s1, const char *s2)
29 {
30    char                ch1, ch2;
31
32    for (;;)
33      {
34         ch1 = toupper(*s1++);
35         ch2 = toupper(*s2++);
36         if (ch1 == '\0' || ch1 != ch2)
37            break;
38      }
39
40    return ch1 - ch2;
41 }
42 #endif
43
44 #ifndef HAVE_STRCASESTR
45 const char         *
46 Estrcasestr(const char *haystack, const char *needle)
47 {
48    const char         *s1, *s2;
49    char                ch1, ch2;
50
51    for (;; haystack++)
52      {
53         s1 = haystack;
54         s2 = needle;
55         if (*s1 == '\0')
56            break;
57         for (;;)
58           {
59              ch1 = toupper(*s1++);
60              ch2 = toupper(*s2++);
61              if (ch2 == '\0')
62                 return haystack;
63              if (ch1 == '\0' || ch1 != ch2)
64                 break;
65           }
66      }
67    return NULL;
68 }
69 #endif