mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-02 23:23:51 +00:00
util: virstring: Remove virStringListJoin
The glib alternative is now used everywhere. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
480fecaa21
commit
cafde24a9a
@ -3241,7 +3241,6 @@ virStringHasSuffix;
|
||||
virStringIsEmpty;
|
||||
virStringIsPrintable;
|
||||
virStringListFreeCount;
|
||||
virStringListJoin;
|
||||
virStringListMerge;
|
||||
virStringMatch;
|
||||
virStringMatchesNameSuffix;
|
||||
|
@ -35,12 +35,6 @@
|
||||
|
||||
VIR_LOG_INIT("util.string");
|
||||
|
||||
/*
|
||||
* The following virStringSplit & virStringListJoin methods
|
||||
* are derived from g_strsplit / g_strjoin in glib2,
|
||||
* also available under the LGPLv2+ license terms
|
||||
*/
|
||||
|
||||
/**
|
||||
* virStringSplitCount:
|
||||
*
|
||||
@ -61,36 +55,6 @@ virStringSplitCount(const char *string,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStringListJoin:
|
||||
* @strings: a NULL-terminated array of strings to join
|
||||
* @delim: a string to insert between each of the strings
|
||||
*
|
||||
* Joins a number of strings together to form one long string, with the
|
||||
* @delim inserted between each of them. The returned string
|
||||
* should be freed with VIR_FREE().
|
||||
*
|
||||
* Returns: a newly-allocated string containing all of the strings joined
|
||||
* together, with @delim between them
|
||||
*/
|
||||
char *virStringListJoin(const char **strings,
|
||||
const char *delim)
|
||||
{
|
||||
char *ret;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
while (*strings) {
|
||||
virBufferAdd(&buf, *strings, -1);
|
||||
if (*(strings+1))
|
||||
virBufferAdd(&buf, delim, -1);
|
||||
strings++;
|
||||
}
|
||||
ret = virBufferContentAndReset(&buf);
|
||||
if (!ret)
|
||||
ret = g_strdup("");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStringListMerge:
|
||||
* @dst: a NULL-terminated array of strings to expand
|
||||
|
@ -28,10 +28,6 @@ char **virStringSplitCount(const char *string,
|
||||
size_t *tokcount)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
|
||||
|
||||
char *virStringListJoin(const char **strings,
|
||||
const char *delim)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
int virStringListMerge(char ***dst,
|
||||
char ***src);
|
||||
|
||||
|
@ -82,12 +82,6 @@ struct testSplitData {
|
||||
};
|
||||
|
||||
|
||||
struct testJoinData {
|
||||
const char *string;
|
||||
const char *delim;
|
||||
const char **tokens;
|
||||
};
|
||||
|
||||
static int testSplit(const void *args)
|
||||
{
|
||||
const struct testSplitData *data = args;
|
||||
@ -140,29 +134,6 @@ static int testSplit(const void *args)
|
||||
}
|
||||
|
||||
|
||||
static int testJoin(const void *args)
|
||||
{
|
||||
const struct testJoinData *data = args;
|
||||
char *got;
|
||||
int ret = -1;
|
||||
|
||||
if (!(got = virStringListJoin(data->tokens, data->delim))) {
|
||||
VIR_DEBUG("Got no result");
|
||||
return -1;
|
||||
}
|
||||
if (STRNEQ(got, data->string)) {
|
||||
fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(got);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testStringSortCompare(const void *opaque G_GNUC_UNUSED)
|
||||
{
|
||||
@ -606,15 +577,8 @@ mymain(void)
|
||||
.max_tokens = max, \
|
||||
.tokens = toks, \
|
||||
}; \
|
||||
struct testJoinData joinData = { \
|
||||
.string = str, \
|
||||
.delim = del, \
|
||||
.tokens = toks, \
|
||||
}; \
|
||||
if (virTestRun("Split " #str, testSplit, &splitData) < 0) \
|
||||
ret = -1; \
|
||||
if (virTestRun("Join " #str, testJoin, &joinData) < 0) \
|
||||
ret = -1; \
|
||||
} while (0)
|
||||
|
||||
VIR_WARNINGS_NO_DECLARATION_AFTER_STATEMENT
|
||||
|
Loading…
x
Reference in New Issue
Block a user