From: Bruno Haible Date: Tue, 9 Jan 2007 14:10:28 +0000 (+0000) Subject: New modules 'unistr/u8-strstr', 'unistr/u16-strstr', 'unistr/u32-strstr'. X-Git-Tag: cvs-readonly~1373 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=46f74723b3fd5b41bebc0fd9c10b642726a0d47e;p=gnulib.git New modules 'unistr/u8-strstr', 'unistr/u16-strstr', 'unistr/u32-strstr'. --- diff --git a/lib/unistr/u-strstr.h b/lib/unistr/u-strstr.h new file mode 100644 index 000000000..1c2e4cb60 --- /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 , 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 000000000..eca5ad676 --- /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 , 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 + +/* 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 000000000..4bcb3bea9 --- /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 , 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 + +/* 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 000000000..a818e3ef0 --- /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 , 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 + +/* 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 000000000..c98dc7174 --- /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 000000000..a24e6061d --- /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 000000000..ea9c6ce61 --- /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 +