diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-17 11:19:47 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-17 11:26:30 +0200 |
commit | 832adf323eaa958bf5d0b0cb6305448c194be561 (patch) | |
tree | 31eb31efc02783705614368a7b21b578c4e7265f /shared/nm-utils | |
parent | b5a86c10a06584cc64bab9e74226b48f12c9d5b1 (diff) | |
download | NetworkManager-832adf323eaa958bf5d0b0cb6305448c194be561.tar.gz |
shared: add nm_utils_escaped_tokens_escape_gstr_assert()
Diffstat (limited to 'shared/nm-utils')
-rw-r--r-- | shared/nm-utils/nm-shared-utils.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 4591cc8e9a..6bfc37acbf 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -422,6 +422,39 @@ const char *nm_utils_escaped_tokens_escape (const char *str, char **out_to_free); static inline GString * +nm_utils_escaped_tokens_escape_gstr_assert (const char *str, + const char *delimiters, + GString *gstring) +{ +#if NM_MORE_ASSERTS > 0 + + /* Just appends @str to @gstring, but also assert that + * no escaping is necessary. + * + * Use nm_utils_escaped_tokens_escape_gstr_assert() instead + * of nm_utils_escaped_tokens_escape_gstr(), if you *know* that + * @str contains no delimiters, no backslashes, and no trailing + * whitespace that requires escaping. */ + + nm_assert (str); + nm_assert (gstring); + nm_assert (delimiters); + + { + gs_free char *str_to_free = NULL; + const char *str0; + + str0 = nm_utils_escaped_tokens_escape (str, delimiters, &str_to_free); + nm_assert (str0 == str); + nm_assert (!str_to_free); + } +#endif + + g_string_append (gstring, str); + return gstring; +} + +static inline GString * nm_utils_escaped_tokens_escape_gstr (const char *str, const char *delimiters, GString *gstring) |