Add macro string_sets (like string_cats)

This commit is contained in:
Patrick Pelissier committed 2021-01-10 09:51:38 +01:00
1 parent 5f05c1e169
commit 8a9d5f6a00
3 files changed
+11

No files matched your search

+5
View File
@@ -5020,6 +5020,11 @@ NOTE: v2 can also be a 'const char *' in C11.
Append all the strings 'v2' ... to the string 'v'.
NOTE: v2 can also be a 'const char *' in C11.
##### void string\_sets(string\_t v, const string\_t v2[, ...] )
Set the string 'v' to the concatenation of all the strings 'v2'
NOTE: v2 can also be a 'const char *' in C11.
##### int string\_cmp\_str(const string\_t v1, const char str[])
##### int string\_cmp(const string\_t v1, const string\_t str)
+4
View File
@@ -1859,6 +1859,10 @@ namespace m_lib {
#define string_cats(a, ...) \
M_MAP2_C(string_cat, a, __VA_ARGS__)
/* Set a string to a set strings (or const char * if C1)) */
#define string_sets(a, ...) \
(string_clean(a), M_MAP2_C(string_cat, a, __VA_ARGS__) )
/* Macro encapsulation for C11 */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+2
View File
@@ -302,6 +302,8 @@ static void test0(void)
string_set_str(s3, " world");
string_cats(s1, s2, s3);
assert (string_cmp_str (s1, "Hello world") == 0);
string_sets(s1, s2, s3);
assert (string_cmp_str (s1, "o world") == 0);
}
string_clear (s1);