summaryrefslogtreecommitdiff
path: root/libgammu/misc/string.c
diff options
context:
space:
mode:
authorMichal Čihař <nijel@debian.org>2017-06-30 15:35:46 +0200
committerMichal Čihař <nijel@debian.org>2017-06-30 15:35:46 +0200
commit2c605769ea566cb79b7684b4c3b6a9f5740e858c (patch)
treec46d5f005d026d0ab1e73d67815d4e9141190fc6 /libgammu/misc/string.c
parentb4bcd4b358a5ed9701642d1f8153306363374047 (diff)
parentab91c30e54a279ee9f8f7c5a63a597860c99a705 (diff)
Updated version 1.38.4 from 'upstream/1.38.4'
with Debian dir 249cb84c262b83b3a28191dde33c1d5a55b5927d
Diffstat (limited to 'libgammu/misc/string.c')
-rw-r--r--libgammu/misc/string.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/libgammu/misc/string.c b/libgammu/misc/string.c
new file mode 100644
index 0000000..8d502b9
--- /dev/null
+++ b/libgammu/misc/string.c
@@ -0,0 +1,115 @@
+#include "string.h"
+
+#include <gammu-unicode.h>
+
+#include <ctype.h>
+
+#ifndef HAVE_STRCASESTR
+/**
+ * Find the first occurrence of find in s, ignore case.
+ * Copyright (c) 1990, 1993 The Regents of the University of California.
+ */
+char *strcasestr(const char *s, const char *find)
+{
+ char c, sc;
+ size_t len;
+
+ if ((c = *find++) != 0) {
+ c = tolower((unsigned char)c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ } while ((char)tolower((unsigned char)sc) != c);
+ } while (strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return (char *)s;
+}
+#endif
+
+#ifndef HAVE_STRCHRNUL
+char *strchrnul(char *s, int find)
+{
+ char *ret;
+ ret = strchr(s, find);
+ if (ret == NULL) return s + strlen(s);
+ return ret;
+}
+#endif
+
+
+#ifdef INTERNAL_STRNCASECMP
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+/**
+ * Case insensitive string comparator
+ * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
+ */
+int strncasecmp (const char *s1, const char *s2, size_t n)
+{
+ register const unsigned char *p1 = (const unsigned char *) s1;
+ register const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+
+ if (p1 == p2 || n == 0)
+ return 0;
+
+ do {
+ c1 = TOLOWER (*p1);
+ c2 = TOLOWER (*p2);
+
+ if (--n == 0 || c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ } while (c1 == c2);
+
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
+#undef TOLOWER
+#endif
+
+#ifdef INTERNAL_STRCASECMP
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+/**
+ * Case insensitive string comparator
+ * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
+ */
+int strcasecmp (const char *s1, const char *s2)
+{
+ register const unsigned char *p1 = (const unsigned char *) s1;
+ register const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+
+ if (p1 == p2)
+ return 0;
+
+ do {
+ c1 = TOLOWER (*p1);
+ c2 = TOLOWER (*p2);
+
+ if (c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ } while (c1 == c2);
+
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
+#undef TOLOWER
+#endif
+
+#ifndef HAVE_TOWLOWER
+/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */
+wchar_t towlower(wchar_t c)
+{
+ unsigned char dest[10];
+
+ DecodeWithUnicodeAlphabet(c, dest);
+ return tolower(dest[0]);
+}
+#endif
+