changeset 27536:2329bef10514

New modules 'unistr/u8-strstr', 'unistr/u16-strstr', 'unistr/u32-strstr'.
author Bruno Haible <bruno@clisp.org>
date Tue, 09 Jan 2007 14:10:28 +0000
parents c2269f25908b
children 17ffd88cb714
files lib/unistr/u-strstr.h lib/unistr/u16-strstr.c lib/unistr/u32-strstr.c lib/unistr/u8-strstr.c modules/unistr/u16-strstr modules/unistr/u32-strstr modules/unistr/u8-strstr
diffstat 7 files changed, 211 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/unistr/u-strstr.h	Tue Jan 09 14:10:28 2007 +0000
@@ -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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/unistr/u16-strstr.c	Tue Jan 09 14:10:28 2007 +0000
@@ -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"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/unistr/u32-strstr.c	Tue Jan 09 14:10:28 2007 +0000
@@ -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"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/unistr/u8-strstr.c	Tue Jan 09 14:10:28 2007 +0000
@@ -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"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/unistr/u16-strstr	Tue Jan 09 14:10:28 2007 +0000
@@ -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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/unistr/u32-strstr	Tue Jan 09 14:10:28 2007 +0000
@@ -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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/unistr/u8-strstr	Tue Jan 09 14:10:28 2007 +0000
@@ -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
+