Mercurial > hg > octave-kai > gnulib-hg
changeset 11454:69468d0eccbe
New module 'unistr/u8-cmp2'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 05 Apr 2009 12:34:14 +0200 |
parents | e9190cf184a2 |
children | b4b545a72158 |
files | ChangeLog lib/unistr.h lib/unistr/u-cmp2.h lib/unistr/u8-cmp2.c modules/unistr/u8-cmp2 |
diffstat | 5 files changed, 103 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-04-05 Bruno Haible <bruno@clisp.org> + + 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 <bruno@clisp.org> * lib/unictype.h (uc_property_is_valid): New macro.
--- a/lib/unistr.h +++ b/lib/unistr.h @@ -402,6 +402,15 @@ 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 *
new file mode 100644 --- /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 <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) +{ + 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; +}
new file mode 100644 --- /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 <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 "unistr.h" + +#include "minmax.h" + +#define FUNC u8_cmp2 +#define UNIT uint8_t +#define U_CMP u8_cmp +#include "u-cmp2.h"
new file mode 100644 --- /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 +