changeset 11383:664a93b85ce6

New module 'unicase/ulc-casecmp'.
author Bruno Haible <bruno@clisp.org>
date Mon, 09 Mar 2009 01:47:38 +0100
parents f19b7a607d51
children 78966a6aa71f
files ChangeLog lib/unicase.h lib/unicase/u-casecmp.h lib/unicase/u16-casecmp.c lib/unicase/u32-casecmp.c lib/unicase/u8-casecmp.c lib/unicase/ulc-casecmp.c modules/unicase/ulc-casecmp
diffstat 8 files changed, 121 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-03-08  Bruno Haible  <bruno@clisp.org>
 
+	New module 'unicase/ulc-casecmp'.
+	* lib/unicase.h (ulc_casecmp): New declaration.
+	* lib/unicase/ulc-casecmp.c: New file.
+	* lib/unicase/u-casecmp.h (FUNC): Change argument types to
+	'const SRC_UNIT *'.
+	* lib/unicase/u8-casecmp.c (SRC_UNIT): Define like UNIT.
+	* lib/unicase/u16-casecmp.c (SRC_UNIT): Likewise.
+	* lib/unicase/u32-casecmp.c (SRC_UNIT): Likewise.
+	* modules/unicase/ulc-casecmp: New file.
+
 	Tests for module 'unicase/u32-is-cased'.
 	* modules/unicase/u32-is-cased-tests: New file.
 	* tests/unicase/test-u32-is-cased.c: New file.
--- a/lib/unicase.h
+++ b/lib/unicase.h
@@ -166,6 +166,10 @@
        u32_casecmp (const uint32_t *s1, size_t n1,
 		    const uint32_t *s2, size_t n2,
 		    const char *iso639_language, uninorm_t nf, int *resultp);
+extern int
+       ulc_casecmp (const char *s1, size_t n1,
+		    const char *s2, size_t n2,
+		    const char *iso639_language, uninorm_t nf, int *resultp);
 
 /* Converts the string S of length N to a string in locale encoding, in such a
    way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with memcmp2() is
--- a/lib/unicase/u-casecmp.h
+++ b/lib/unicase/u-casecmp.h
@@ -16,7 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 int
-FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
+FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2,
       const char *iso639_language, uninorm_t nf, int *resultp)
 {
   UNIT buf1[2048 / sizeof (UNIT)];
--- a/lib/unicase/u16-casecmp.c
+++ b/lib/unicase/u16-casecmp.c
@@ -29,6 +29,7 @@
 
 #define FUNC u16_casecmp
 #define UNIT uint16_t
+#define SRC_UNIT uint16_t
 #define U_CASEFOLD u16_casefold
 #define U_CMP u16_cmp
 #include "u-casecmp.h"
--- a/lib/unicase/u32-casecmp.c
+++ b/lib/unicase/u32-casecmp.c
@@ -29,6 +29,7 @@
 
 #define FUNC u32_casecmp
 #define UNIT uint32_t
+#define SRC_UNIT uint32_t
 #define U_CASEFOLD u32_casefold
 #define U_CMP u32_cmp
 #include "u-casecmp.h"
--- a/lib/unicase/u8-casecmp.c
+++ b/lib/unicase/u8-casecmp.c
@@ -29,6 +29,7 @@
 
 #define FUNC u8_casecmp
 #define UNIT uint8_t
+#define SRC_UNIT uint8_t
 #define U_CASEFOLD u8_casefold
 #define U_CMP u8_cmp
 #include "u-casecmp.h"
new file mode 100644
--- /dev/null
+++ b/lib/unicase/ulc-casecmp.c
@@ -0,0 +1,73 @@
+/* Case and normalization insensitive comparison of strings.
+   Copyright (C) 2009 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+   This program is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published
+   by the Free Software Foundation; either version 3 of the License, 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "unicase.h"
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "minmax.h"
+#include "uninorm.h"
+#include "uniconv.h"
+#include "unistr.h"
+
+static uint8_t *
+ulc_u8_casefold (const char *s, size_t n, const char *iso639_language,
+		 uninorm_t nf,
+		 uint8_t *resultbuf, size_t *lengthp)
+{
+  uint8_t convbuf[2048 / sizeof (uint8_t)];
+  uint8_t *conv;
+  size_t conv_length;
+  uint8_t *result;
+
+  /* Convert the string to UTF-8.  */
+  conv = convbuf;
+  conv_length = sizeof (convbuf) / sizeof (uint8_t);
+  if (u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
+			     &conv, &conv_length) < 0)
+    /* errno is set here.  */
+    return NULL;
+
+  /* Case-fold and normalize.  */
+  result = u8_casefold (conv, conv_length, iso639_language, nf,
+			resultbuf, lengthp);
+  if (result == NULL)
+    {
+      if (conv != convbuf)
+	{
+	  int saved_errno = errno;
+	  free (conv);
+	  errno = saved_errno;
+	}
+      return NULL;
+    }
+
+  if (conv != convbuf)
+    free (conv);
+  return result;
+}
+
+#define FUNC ulc_casecmp
+#define UNIT uint8_t
+#define SRC_UNIT char
+#define U_CASEFOLD ulc_u8_casefold
+#define U_CMP u8_cmp
+#include "u-casecmp.h"
new file mode 100644
--- /dev/null
+++ b/modules/unicase/ulc-casecmp
@@ -0,0 +1,30 @@
+Description:
+Case and normalization insensitive comparison of strings.
+
+Files:
+lib/unicase/ulc-casecmp.c
+lib/unicase/u-casecmp.h
+
+Depends-on:
+unicase/base
+unicase/u8-casefold
+uninorm/decomposing-form
+uniconv/u8-conv-from-enc
+unistr/u8-cmp
+localcharset
+minmax
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += unicase/ulc-casecmp.c
+
+Include:
+"unicase.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+