]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
str-list: Add a remove function.
authorBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2020 21:29:17 +0000 (23:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2020 22:23:15 +0000 (00:23 +0200)
* gettext-tools/src/str-list.h (string_list_remove): New declaration.
* gettext-tools/src/str-list.c (string_list_remove): New function.

gettext-tools/src/str-list.c
gettext-tools/src/str-list.h

index 9b72eaed44cfc3f7c36c01bd79fc1ad9316f80ee..b2c9cf24c96ab696be1fc1c5ed984cdb4bcdcf23 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995, 1998, 2000-2004, 2006, 2009 Free Software
+   Copyright (C) 1995, 1998, 2000-2004, 2006, 2009, 2020 Free Software
    Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
@@ -235,3 +235,23 @@ string_list_member (const string_list_ty *slp, const char *s)
       return true;
   return false;
 }
+
+
+/* Remove s from the list of strings.  Return the removed string or NULL.  */
+const char *
+string_list_remove (string_list_ty *slp, const char *s)
+{
+  size_t j;
+
+  for (j = 0; j < slp->nitems; ++j)
+    if (strcmp (slp->item[j], s) == 0)
+      {
+        const char *found = slp->item[j];
+        slp->nitems--;
+        if (slp->nitems > j)
+          memmove (&slp->item[j + 1], &slp->item[j],
+                   (slp->nitems - j) * sizeof (const char *));
+        return found;
+      }
+  return NULL;
+}
index 57cc7c33ae5340176988178e22c4784dc566df12..483d3c2b1652ce40a4392d8178417b5c3955a5ed 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1996, 1998, 2000-2004, 2009 Free Software
+   Copyright (C) 1995-1996, 1998, 2000-2004, 2009, 2020 Free Software
    Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
@@ -80,6 +80,9 @@ extern char *string_list_join (const string_list_ty *slp, const char *separator,
 /* Return 1 if s is contained in the list of strings, 0 otherwise.  */
 extern bool string_list_member (const string_list_ty *slp, const char *s);
 
+/* Remove s from the list of strings.  Return the removed string or NULL.  */
+extern const char * string_list_remove (string_list_ty *slp, const char *s);
+
 
 #ifdef __cplusplus
 }