wrong character in the GSM 03.38 table (ç for Ç)
[gammu.git] / helper / string.c
blob8d502b956585342450fa449696e7418f8ae9bd29
1 #include "string.h"
3 #include <gammu-unicode.h>
5 #include <ctype.h>
7 #ifndef HAVE_STRCASESTR
8 /**
9 * Find the first occurrence of find in s, ignore case.
10 * Copyright (c) 1990, 1993 The Regents of the University of California.
12 char *strcasestr(const char *s, const char *find)
14 char c, sc;
15 size_t len;
17 if ((c = *find++) != 0) {
18 c = tolower((unsigned char)c);
19 len = strlen(find);
20 do {
21 do {
22 if ((sc = *s++) == 0)
23 return (NULL);
24 } while ((char)tolower((unsigned char)sc) != c);
25 } while (strncasecmp(s, find, len) != 0);
26 s--;
28 return (char *)s;
30 #endif
32 #ifndef HAVE_STRCHRNUL
33 char *strchrnul(char *s, int find)
35 char *ret;
36 ret = strchr(s, find);
37 if (ret == NULL) return s + strlen(s);
38 return ret;
40 #endif
43 #ifdef INTERNAL_STRNCASECMP
44 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
45 /**
46 * Case insensitive string comparator
47 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
49 int strncasecmp (const char *s1, const char *s2, size_t n)
51 register const unsigned char *p1 = (const unsigned char *) s1;
52 register const unsigned char *p2 = (const unsigned char *) s2;
53 unsigned char c1, c2;
55 if (p1 == p2 || n == 0)
56 return 0;
58 do {
59 c1 = TOLOWER (*p1);
60 c2 = TOLOWER (*p2);
62 if (--n == 0 || c1 == '\0')
63 break;
65 ++p1;
66 ++p2;
67 } while (c1 == c2);
69 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
71 #undef TOLOWER
72 #endif
74 #ifdef INTERNAL_STRCASECMP
75 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
76 /**
77 * Case insensitive string comparator
78 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
80 int strcasecmp (const char *s1, const char *s2)
82 register const unsigned char *p1 = (const unsigned char *) s1;
83 register const unsigned char *p2 = (const unsigned char *) s2;
84 unsigned char c1, c2;
86 if (p1 == p2)
87 return 0;
89 do {
90 c1 = TOLOWER (*p1);
91 c2 = TOLOWER (*p2);
93 if (c1 == '\0')
94 break;
96 ++p1;
97 ++p2;
98 } while (c1 == c2);
100 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
102 #undef TOLOWER
103 #endif
105 #ifndef HAVE_TOWLOWER
106 /* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */
107 wchar_t towlower(wchar_t c)
109 unsigned char dest[10];
111 DecodeWithUnicodeAlphabet(c, dest);
112 return tolower(dest[0]);
114 #endif