From 80ae500d4237e39ce2c63aea80b2a34e5887ce90 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 9 Mar 2009 01:47:38 +0100 Subject: [PATCH] New module 'unicase/ulc-casecmp'. --- ChangeLog | 10 +++++++ lib/unicase.h | 4 +++ lib/unicase/u-casecmp.h | 2 +- lib/unicase/u16-casecmp.c | 1 + lib/unicase/u32-casecmp.c | 1 + lib/unicase/u8-casecmp.c | 1 + lib/unicase/ulc-casecmp.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ modules/unicase/ulc-casecmp | 30 +++++++++++++++++++ 8 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 lib/unicase/ulc-casecmp.c create mode 100644 modules/unicase/ulc-casecmp diff --git a/ChangeLog b/ChangeLog index 80d974fb7..c93445565 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2009-03-08 Bruno Haible + 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. diff --git a/lib/unicase.h b/lib/unicase.h index 63fd86232..a19d2f722 100644 --- a/lib/unicase.h +++ b/lib/unicase.h @@ -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 diff --git a/lib/unicase/u-casecmp.h b/lib/unicase/u-casecmp.h index 50325b095..8ae23d703 100644 --- a/lib/unicase/u-casecmp.h +++ b/lib/unicase/u-casecmp.h @@ -16,7 +16,7 @@ along with this program. If not, see . */ 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)]; diff --git a/lib/unicase/u16-casecmp.c b/lib/unicase/u16-casecmp.c index ca591328c..b4777f54e 100644 --- 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" diff --git a/lib/unicase/u32-casecmp.c b/lib/unicase/u32-casecmp.c index ede936c0f..a691c43d3 100644 --- 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" diff --git a/lib/unicase/u8-casecmp.c b/lib/unicase/u8-casecmp.c index 3b303420a..b7e250af2 100644 --- 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" diff --git a/lib/unicase/ulc-casecmp.c b/lib/unicase/ulc-casecmp.c new file mode 100644 index 000000000..b337ee2f6 --- /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 , 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 . */ + +#include + +/* Specification. */ +#include "unicase.h" + +#include +#include + +#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 index 000000000..618ae286e --- /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 + -- 2.11.0