+2009-03-06 Bruno Haible <bruno@clisp.org>
+
+ New module 'uninorm/u8-normcmp'.
+ * lib/uninorm.h (u8_normcmp, u16_normcmp, u32_normcmp): New
+ declarations.
+ * lib/uninorm/u8-normcmp.c: New file.
+ * lib/uninorm/u-normcmp.h: New file.
+ * modules/uninorm/u8-normcmp: New file.
+
2009-03-06 Bruno Haible <bruno@clisp.org>
* lib/w32spawn.h (dup_noinherit): Add cast, to avoid gcc warning.
uint32_t *resultbuf, size_t *lengthp);
+/* Compare S1 and S2, ignoring normalization.
+ NF must be either UNINORM_NFD or UNINORM_NFKD.
+ If successful, set *RESULT to -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2, and
+ return 0. Upon failure, return the error number. */
+extern int
+ u8_normcmp (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2,
+ uninorm_t nf, int *result);
+extern int
+ u16_normcmp (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2,
+ uninorm_t nf, int *result);
+extern int
+ u32_normcmp (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2,
+ uninorm_t nf, int *result);
+
+
/* Normalization of a stream of Unicode characters.
A "stream of Unicode characters" is essentially a function that accepts an
--- /dev/null
+/* Normalization insensitive comparison of UTF-8 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/>. */
+
+int
+FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
+ uninorm_t nf, int *result)
+{
+ UNIT *norms1;
+ size_t norms1_length;
+ UNIT *norms2;
+ size_t norms2_length;
+ int cmp;
+
+ /* Normalize S1. */
+ norms1 = U_NORMALIZE (nf, s1, n1, NULL, &norms1_length);
+ if (norms1 == NULL)
+ return errno;
+
+ /* Normalize S2. */
+ norms2 = U_NORMALIZE (nf, s2, n2, NULL, &norms2_length);
+ if (norms2 == NULL)
+ {
+ int saved_errno = errno;
+ free (norms1);
+ return saved_errno;
+ }
+
+ /* Compare the normalized strings. */
+ cmp = U_CMP (norms1, norms2, MIN (norms1_length, norms2_length));
+ if (cmp == 0)
+ {
+ if (norms1_length < norms2_length)
+ cmp = -1;
+ else if (norms1_length > norms2_length)
+ cmp = 1;
+ }
+ else if (cmp > 0)
+ cmp = 1;
+ else if (cmp < 0)
+ cmp = -1;
+
+ free (norms2);
+ free (norms1);
+ *result = cmp;
+ return 0;
+}
--- /dev/null
+/* Normalization insensitive comparison of UTF-8 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 "uninorm.h"
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "minmax.h"
+#include "unistr.h"
+
+#define FUNC u8_normcmp
+#define UNIT uint8_t
+#define U_NORMALIZE u8_normalize
+#define U_CMP u8_cmp
+#include "u-normcmp.h"
--- /dev/null
+Description:
+Normalization insensitive comparison of UTF-8 strings.
+
+Files:
+lib/uninorm/u8-normcmp.c
+lib/uninorm/u-normcmp.h
+
+Depends-on:
+uninorm/u8-normalize
+unistr/u8-cmp
+minmax
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += uninorm/u8-normcmp.c
+
+Include:
+"uninorm.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+