From aa2af51b11c89831d6611b461908af0a5e0d337c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 5 Apr 2009 12:34:14 +0200 Subject: [PATCH] New module 'unistr/u8-cmp2'. --- ChangeLog | 8 ++++++++ lib/unistr.h | 9 +++++++++ lib/unistr/u-cmp2.h | 32 ++++++++++++++++++++++++++++++++ lib/unistr/u8-cmp2.c | 28 ++++++++++++++++++++++++++++ modules/unistr/u8-cmp2 | 26 ++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 lib/unistr/u-cmp2.h create mode 100644 lib/unistr/u8-cmp2.c create mode 100644 modules/unistr/u8-cmp2 diff --git a/ChangeLog b/ChangeLog index 2e91973f3..e84e1b176 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2009-04-05 Bruno Haible + New module 'unistr/u8-cmp2'. + * lib/unistr.h (u8_cmp2, u16_cmp2, u32_cmp2): New declarations. + * lib/unistr/u8-cmp2.c: New file. + * lib/unistr/u-cmp2.h: New file. + * modules/unistr/u8-cmp2: New file. + +2009-04-05 Bruno Haible + * lib/unictype.h (uc_property_is_valid): New macro. * tests/unictype/test-pr_byname.c (main): Use it. diff --git a/lib/unistr.h b/lib/unistr.h index 0d2c19d98..16b26693a 100644 --- a/lib/unistr.h +++ b/lib/unistr.h @@ -402,6 +402,15 @@ extern int extern int u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n); +/* Compare S1 and S2. */ +/* Similar to memcmp2(). */ +extern int + u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2); +extern int + u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2); +extern int + u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2); + /* Search the string at S for UC. */ /* Similar to memchr(). */ extern uint8_t * diff --git a/lib/unistr/u-cmp2.h b/lib/unistr/u-cmp2.h new file mode 100644 index 000000000..ae3750c48 --- /dev/null +++ b/lib/unistr/u-cmp2.h @@ -0,0 +1,32 @@ +/* Compare pieces of UTF-8/UTF-16/UTF-32 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 . */ + +int +FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2) +{ + int cmp = U_CMP (s1, s2, MIN (n1, n2)); + + if (cmp == 0) + { + if (n1 < n2) + cmp = -1; + else if (n1 > n2) + cmp = 1; + } + + return cmp; +} diff --git a/lib/unistr/u8-cmp2.c b/lib/unistr/u8-cmp2.c new file mode 100644 index 000000000..99cee9f2c --- /dev/null +++ b/lib/unistr/u8-cmp2.c @@ -0,0 +1,28 @@ +/* Compare pieces of UTF-8 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 "unistr.h" + +#include "minmax.h" + +#define FUNC u8_cmp2 +#define UNIT uint8_t +#define U_CMP u8_cmp +#include "u-cmp2.h" diff --git a/modules/unistr/u8-cmp2 b/modules/unistr/u8-cmp2 new file mode 100644 index 000000000..9fbbc4346 --- /dev/null +++ b/modules/unistr/u8-cmp2 @@ -0,0 +1,26 @@ +Description: +Compare pieces of UTF-8 strings with possibly different lengths. + +Files: +lib/unistr/u8-cmp2.c +lib/unistr/u-cmp2.h + +Depends-on: +unistr/base +unistr/u8-cmp +minmax + +configure.ac: + +Makefile.am: +lib_SOURCES += unistr/u8-cmp2.c + +Include: +"unistr.h" + +License: +LGPL + +Maintainer: +Bruno Haible + -- 2.11.0