New modules 'unistr/u8-strstr', 'unistr/u16-strstr', 'unistr/u32-strstr'.
authorBruno Haible <bruno@clisp.org>
Tue, 9 Jan 2007 14:10:28 +0000 (14:10 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Jan 2007 14:10:28 +0000 (14:10 +0000)
lib/unistr/u-strstr.h [new file with mode: 0644]
lib/unistr/u16-strstr.c [new file with mode: 0644]
lib/unistr/u32-strstr.c [new file with mode: 0644]
lib/unistr/u8-strstr.c [new file with mode: 0644]
modules/unistr/u16-strstr [new file with mode: 0644]
modules/unistr/u32-strstr [new file with mode: 0644]
modules/unistr/u8-strstr [new file with mode: 0644]

diff --git a/lib/unistr/u-strstr.h b/lib/unistr/u-strstr.h
new file mode 100644 (file)
index 0000000..1c2e4cb
--- /dev/null
@@ -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 (file)
index 0000000..eca5ad6
--- /dev/null
@@ -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 (file)
index 0000000..4bcb3be
--- /dev/null
@@ -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 (file)
index 0000000..a818e3e
--- /dev/null
@@ -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 (file)
index 0000000..c98dc71
--- /dev/null
@@ -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 (file)
index 0000000..a24e606
--- /dev/null
@@ -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 (file)
index 0000000..ea9c6ce
--- /dev/null
@@ -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
+