New module 'unicase/ulc-casexfrm'.
authorBruno Haible <bruno@clisp.org>
Tue, 10 Mar 2009 01:38:00 +0000 (02:38 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 10 Mar 2009 01:38:00 +0000 (02:38 +0100)
ChangeLog
lib/unicase.h
lib/unicase/ulc-casexfrm.c [new file with mode: 0644]
modules/unicase/ulc-casexfrm [new file with mode: 0644]

index f16e411..f4d4264 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-08  Bruno Haible  <bruno@clisp.org>
+
+       New module 'unicase/ulc-casexfrm'.
+       * lib/unicase.h (ulc_casexfrm): New declaration.
+       * lib/unicase/ulc-casexfrm.c: New file.
+       * modules/unicase/ulc-casexfrm: New file.
+
 2009-03-09  Bruno Haible  <bruno@clisp.org>
 
        Followup to 2008-12-22 commit: Remove unnecessary AC_FUNC_MBRTOWC
index a19d2f7..ca3ab32 100644 (file)
@@ -184,6 +184,9 @@ extern char *
 extern char *
        u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language,
                     uninorm_t nf, char *resultbuf, size_t *lengthp);
+extern char *
+       ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
+                    uninorm_t nf, char *resultbuf, size_t *lengthp);
 
 /* Compare S1 and S2, ignoring differences in case and normalization, using the
    collation rules of the current locale.
diff --git a/lib/unicase/ulc-casexfrm.c b/lib/unicase/ulc-casexfrm.c
new file mode 100644 (file)
index 0000000..00009f8
--- /dev/null
@@ -0,0 +1,63 @@
+/* Locale dependent transformation for case 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 "uniconv.h"
+
+char *
+ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
+             uninorm_t nf,
+             char *resultbuf, size_t *lengthp)
+{
+  uint8_t convbuf[2048 / sizeof (uint8_t)];
+  uint8_t *conv;
+  size_t conv_length;
+  char *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_casexfrm (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;
+}
diff --git a/modules/unicase/ulc-casexfrm b/modules/unicase/ulc-casexfrm
new file mode 100644 (file)
index 0000000..48e2eca
--- /dev/null
@@ -0,0 +1,26 @@
+Description:
+Locale dependent transformation for case insensitive comparison of strings.
+
+Files:
+lib/unicase/ulc-casexfrm.c
+
+Depends-on:
+unicase/base
+unicase/u8-casexfrm
+uniconv/u8-conv-from-enc
+localcharset
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += unicase/ulc-casexfrm.c
+
+Include:
+"unicase.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+