New module 'unistr/u8-cmp2'.
authorBruno Haible <bruno@clisp.org>
Sun, 5 Apr 2009 10:34:14 +0000 (12:34 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Apr 2009 10:34:14 +0000 (12:34 +0200)
ChangeLog
lib/unistr.h
lib/unistr/u-cmp2.h [new file with mode: 0644]
lib/unistr/u8-cmp2.c [new file with mode: 0644]
modules/unistr/u8-cmp2 [new file with mode: 0644]

index 2e91973..e84e1b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 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.
        * tests/unictype/test-pr_byname.c (main): Use it.
 
index 0d2c19d..16b2669 100644 (file)
@@ -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 (file)
index 0000000..ae3750c
--- /dev/null
@@ -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;
+}
diff --git a/lib/unistr/u8-cmp2.c b/lib/unistr/u8-cmp2.c
new file mode 100644 (file)
index 0000000..99cee9f
--- /dev/null
@@ -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"
diff --git a/modules/unistr/u8-cmp2 b/modules/unistr/u8-cmp2
new file mode 100644 (file)
index 0000000..9fbbc43
--- /dev/null
@@ -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
+