Re: new modules string-desc, xstring-desc, string-desc-quotearg

2023-03-31 Thread Simon Josefsson via Gnulib discussion list
Bruno Haible  writes:

> Thanks for the inputs and feedbacks. Here are the new modules
>   string-desc,
>   xstring-desc,
>   string-desc-quotearg
> that I'm adding.

Thank you for making it library-friendly!  I will try to find some
package and migrate to these tools, rather than to use custom similar
variants.

/Simon


signature.asc
Description: PGP signature


Re: new modules string-desc, xstring-desc, string-desc-quotearg

2023-03-30 Thread Bruno Haible
>   string-desc: Add tests.
>   * tests/test-string-desc.sh: New file.
>   * tests/test-string-desc.c: New file.
>   * modules/string-desc-tests: New file.

Oops, these tests cause a "make distcheck" failure:

  ERROR: files left in build directory after distclean:
  ./gettext-tools/gnulib-tests/test-string-desc.ok
  make[1]: *** [Makefile:699: distcleancheck] Error 1

Fixed as follows.


2023-03-30  Bruno Haible  

string-desc tests: Fix "make distcheck" failure.
* tests/test-string-desc.sh: Run the test in a subdir.

diff --git a/tests/test-string-desc.sh b/tests/test-string-desc.sh
index 1f52ccf19e..57f0e2371b 100755
--- a/tests/test-string-desc.sh
+++ b/tests/test-string-desc.sh
@@ -1,13 +1,12 @@
 #!/bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ .
 
-./test-string-desc${EXEEXT} > test-string-desc-1.tmp 3> test-string-desc-3.tmp 
|| exit 1
+${CHECKER} test-string-desc${EXEEXT} > test-string-desc-1.tmp 3> 
test-string-desc-3.tmp || Exit 1
 
 printf 'Hello world!The\0quick\0brown\0\0fox\0' > test-string-desc.ok
 
 : "${DIFF=diff}"
-${DIFF} test-string-desc.ok test-string-desc-1.tmp || { echo 
"string_desc_fwrite KO" 1>&2; exit 1; }
-${DIFF} test-string-desc.ok test-string-desc-3.tmp || { echo 
"string_desc_write KO" 1>&2; exit 1; }
+${DIFF} test-string-desc.ok test-string-desc-1.tmp || { echo 
"string_desc_fwrite KO" 1>&2; Exit 1; }
+${DIFF} test-string-desc.ok test-string-desc-3.tmp || { echo 
"string_desc_write KO" 1>&2; Exit 1; }
 
-rm -f test-string-desc-1.tmp test-string-desc-3.tmp
-
-exit 0
+Exit 0






new modules string-desc, xstring-desc, string-desc-quotearg

2023-03-28 Thread Bruno Haible
Thanks for the inputs and feedbacks. Here are the new modules
  string-desc,
  xstring-desc,
  string-desc-quotearg
that I'm adding.


2023-03-28  Bruno Haible  

doc: Document string-desc and related modules.
* doc/string-desc.texi: New file.
* doc/gnulib.texi (Particular Modules): Include it.

string-desc-quotearg: Add tests.
* tests/test-string-desc-quotearg.c: New file.
* modules/string-desc-quotearg-tests: New file.

string-desc-quotearg: New module.
* lib/string-desc-quotearg.h: New file.
* lib/string-desc-quotearg.c: New file.
* modules/string-desc-quotearg: New file.

xstring-desc: Add tests.
* tests/test-xstring-desc.c: New file.
* modules/xstring-desc-tests: New file.

xstring-desc: New module.
* lib/xstring-desc.h: New file.
* lib/xstring-desc.c: New file.
* modules/xstring-desc: New file.

string-desc: Add tests.
* tests/test-string-desc.sh: New file.
* tests/test-string-desc.c: New file.
* modules/string-desc-tests: New file.

string-desc: New module.
* lib/string-desc.h: New file.
* lib/string-desc.c: New file.
* lib/string-desc-contains.c: New file.
* modules/string-desc: New file.

From 93e98eb64e33d1a9d5e562fe61f9eb86a2a4de2e Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Wed, 29 Mar 2023 00:22:17 +0200
Subject: [PATCH 1/7] string-desc: New module.

* lib/string-desc.h: New file.
* lib/string-desc.c: New file.
* lib/string-desc-contains.c: New file.
* modules/string-desc: New file.
---
 ChangeLog  |   8 +
 lib/string-desc-contains.c |  44 +
 lib/string-desc.c  | 358 +
 lib/string-desc.h  | 229 
 modules/string-desc|  30 
 5 files changed, 669 insertions(+)
 create mode 100644 lib/string-desc-contains.c
 create mode 100644 lib/string-desc.c
 create mode 100644 lib/string-desc.h
 create mode 100644 modules/string-desc

diff --git a/ChangeLog b/ChangeLog
index 0688e05bd8..2865fdea7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-03-28  Bruno Haible  
+
+	string-desc: New module.
+	* lib/string-desc.h: New file.
+	* lib/string-desc.c: New file.
+	* lib/string-desc-contains.c: New file.
+	* modules/string-desc: New file.
+
 2023-03-28  Bruno Haible  
 
 	doc: Fix placement of memset_explicit node.
diff --git a/lib/string-desc-contains.c b/lib/string-desc-contains.c
new file mode 100644
index 00..c02617629e
--- /dev/null
+++ b/lib/string-desc-contains.c
@@ -0,0 +1,44 @@
+/* String descriptors.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file 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 file 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible , 2023.  */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Specification.  */
+#include "string-desc.h"
+
+#include 
+
+
+/* This function is in a separate compilation unit, because not all users
+   of the 'string-desc' module need this function and it depends on 'memmem'
+   which — depending on platforms — costs up to 2 KB of binary code.  */
+
+ptrdiff_t
+string_desc_contains (string_desc_t haystack, string_desc_t needle)
+{
+  if (needle._nbytes == 0)
+return 0;
+  void *found =
+memmem (haystack._data, haystack._nbytes, needle._data, needle._nbytes);
+  if (found != NULL)
+return (char *) found - haystack._data;
+  else
+return -1;
+}
diff --git a/lib/string-desc.c b/lib/string-desc.c
new file mode 100644
index 00..2747612bbc
--- /dev/null
+++ b/lib/string-desc.c
@@ -0,0 +1,358 @@
+/* String descriptors.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+   This file 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 file 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
+