New module 'unicase/ulc-casecmp'.
authorBruno Haible <bruno@clisp.org>
Mon, 9 Mar 2009 00:47:38 +0000 (01:47 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 9 Mar 2009 00:47:38 +0000 (01:47 +0100)
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 [new file with mode: 0644]
modules/unicase/ulc-casecmp [new file with mode: 0644]

index 80d974f..c934455 100644 (file)
--- 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.
index 63fd862..a19d2f7 100644 (file)
@@ -166,6 +166,10 @@ extern int
        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
index 50325b0..8ae23d7 100644 (file)
@@ -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)];
index ca59132..b4777f5 100644 (file)
@@ -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"
index ede936c..a691c43 100644 (file)
@@ -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"
index 3b30342..b7e250a 100644 (file)
@@ -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"
diff --git a/lib/unicase/ulc-casecmp.c b/lib/unicase/ulc-casecmp.c
new file mode 100644 (file)
index 0000000..b337ee2
--- /dev/null
@@ -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"
diff --git a/modules/unicase/ulc-casecmp b/modules/unicase/ulc-casecmp
new file mode 100644 (file)
index 0000000..618ae28
--- /dev/null
@@ -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
+