summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/unistr/u-strstr.h51
-rw-r--r--lib/unistr/u16-strstr.c30
-rw-r--r--lib/unistr/u32-strstr.c28
-rw-r--r--lib/unistr/u8-strstr.c30
-rw-r--r--modules/unistr/u16-strstr24
-rw-r--r--modules/unistr/u32-strstr24
-rw-r--r--modules/unistr/u8-strstr24
7 files changed, 211 insertions, 0 deletions
diff --git a/lib/unistr/u-strstr.h b/lib/unistr/u-strstr.h
new file mode 100644
index 0000000000..1c2e4cb607
--- /dev/null
+++ b/lib/unistr/u-strstr.h
@@ -0,0 +1,51 @@
+/* Substring test for UTF-8/UTF-16/UTF-32 strings.
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+UNIT *
+FUNC (const UNIT *haystack, const UNIT *needle)
+{
+ UNIT first = needle[0];
+
+ /* Is needle empty? */
+ if (first == 0)
+ return (UNIT *) haystack;
+
+ /* Is needle nearly empty? */
+ if (needle[1] == 0)
+ return U_STRCHR (haystack, first);
+
+ /* Search for needle's first unit. */
+ for (; *haystack != 0; haystack++)
+ if (*haystack == first)
+ {
+ /* Compare with needle's remaining units. */
+ const UNIT *hptr = haystack + 1;
+ const UNIT *nptr = needle + 1;
+ for (;;)
+ {
+ if (*hptr != *nptr)
+ break;
+ hptr++; nptr++;
+ if (*nptr == 0)
+ return (UNIT *) haystack;
+ }
+ }
+
+ return NULL;
+}
diff --git a/lib/unistr/u16-strstr.c b/lib/unistr/u16-strstr.c
new file mode 100644
index 0000000000..eca5ad6768
--- /dev/null
+++ b/lib/unistr/u16-strstr.c
@@ -0,0 +1,30 @@
+/* Substring test for UTF-16 strings.
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistr.h"
+
+/* FIXME: Maybe walking the string via u16_mblen is a win? */
+
+#define FUNC u16_strstr
+#define UNIT uint16_t
+#define U_STRCHR u16_strchr
+#include "u-strstr.h"
diff --git a/lib/unistr/u32-strstr.c b/lib/unistr/u32-strstr.c
new file mode 100644
index 0000000000..4bcb3bea95
--- /dev/null
+++ b/lib/unistr/u32-strstr.c
@@ -0,0 +1,28 @@
+/* Substring test for UTF-32 strings.
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistr.h"
+
+#define FUNC u32_strstr
+#define UNIT uint32_t
+#define U_STRCHR u32_strchr
+#include "u-strstr.h"
diff --git a/lib/unistr/u8-strstr.c b/lib/unistr/u8-strstr.c
new file mode 100644
index 0000000000..a818e3ef0f
--- /dev/null
+++ b/lib/unistr/u8-strstr.c
@@ -0,0 +1,30 @@
+/* Substring test for UTF-8 strings.
+ Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistr.h"
+
+/* FIXME: Maybe walking the string via u8_mblen is a win? */
+
+#define FUNC u8_strstr
+#define UNIT uint8_t
+#define U_STRCHR u8_strchr
+#include "u-strstr.h"
diff --git a/modules/unistr/u16-strstr b/modules/unistr/u16-strstr
new file mode 100644
index 0000000000..c98dc71748
--- /dev/null
+++ b/modules/unistr/u16-strstr
@@ -0,0 +1,24 @@
+Description:
+Substring test for UTF-16 strings.
+
+Files:
+lib/unistr/u16-strstr.c
+lib/unistr/u-strstr.h
+
+Depends-on:
+unistr/base
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += unistr/u16-strstr.c
+
+Include:
+"unistr.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/unistr/u32-strstr b/modules/unistr/u32-strstr
new file mode 100644
index 0000000000..a24e6061db
--- /dev/null
+++ b/modules/unistr/u32-strstr
@@ -0,0 +1,24 @@
+Description:
+Substring test for UTF-32 strings.
+
+Files:
+lib/unistr/u32-strstr.c
+lib/unistr/u-strstr.h
+
+Depends-on:
+unistr/base
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += unistr/u32-strstr.c
+
+Include:
+"unistr.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/unistr/u8-strstr b/modules/unistr/u8-strstr
new file mode 100644
index 0000000000..ea9c6ce61b
--- /dev/null
+++ b/modules/unistr/u8-strstr
@@ -0,0 +1,24 @@
+Description:
+Substring test for UTF-8 strings.
+
+Files:
+lib/unistr/u8-strstr.c
+lib/unistr/u-strstr.h
+
+Depends-on:
+unistr/base
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += unistr/u8-strstr.c
+
+Include:
+"unistr.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+