The glib alternative is now used everywhere.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
virStringIsEmpty;
virStringIsPrintable;
virStringListFreeCount;
-virStringListJoin;
virStringListMerge;
virStringMatch;
virStringMatchesNameSuffix;
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:
*
}
-/**
- * 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
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);
};
-struct testJoinData {
- const char *string;
- const char *delim;
- const char **tokens;
-};
-
static int testSplit(const void *args)
{
const struct testSplitData *data = 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)
{
.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