From: Bruno Haible Date: Sun, 26 Apr 2020 21:29:17 +0000 (+0200) Subject: str-list: Add a remove function. X-Git-Tag: v0.21~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b58c9924145668747a9e9a45f673493ada26062;p=thirdparty%2Fgettext.git str-list: Add a remove function. * gettext-tools/src/str-list.h (string_list_remove): New declaration. * gettext-tools/src/str-list.c (string_list_remove): New function. --- diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c index 9b72eaed4..b2c9cf24c 100644 --- a/gettext-tools/src/str-list.c +++ b/gettext-tools/src/str-list.c @@ -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 @@ -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; +} diff --git a/gettext-tools/src/str-list.h b/gettext-tools/src/str-list.h index 57cc7c33a..483d3c2b1 100644 --- a/gettext-tools/src/str-list.h +++ b/gettext-tools/src/str-list.h @@ -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 @@ -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 }