diff options
author | Thomas Haller <thaller@redhat.com> | 2020-06-20 20:17:25 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-06-26 09:29:53 +0200 |
commit | a5a56565822b892a83273b4444ff866c5cdea112 (patch) | |
tree | af98693add84ac7abaaca68f811811bcc0cc5783 | |
parent | 5222f1b5ff0782248426b42d77996c9c7e226654 (diff) | |
download | NetworkManager-a5a56565822b892a83273b4444ff866c5cdea112.tar.gz |
shared: add nm_utils_escaped_tokens_escape_unnecessary() util
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 43b8288b0a..c16a89b3af 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -631,23 +631,24 @@ nm_utils_escaped_tokens_escape (const char *str, out_to_free); } -static inline GString * -nm_utils_escaped_tokens_escape_gstr_assert (const char *str, - const char *delimiters, - GString *gstring) +/** + * nm_utils_escaped_tokens_escape_unnecessary: + * @str: the string to check for "escape" + * @delimiters: the delimiters + * + * This asserts that calling nm_utils_escaped_tokens_escape() + * on @str has no effect and returns @str directly. This is only + * for asserting that @str is safe to not require any escaping. + * + * Returns: @str + */ +static inline const char * +nm_utils_escaped_tokens_escape_unnecessary (const char *str, + const char *delimiters) { #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); { @@ -660,8 +661,16 @@ nm_utils_escaped_tokens_escape_gstr_assert (const char *str, } #endif - g_string_append (gstring, str); - return gstring; + return str; +} + +static inline void +nm_utils_escaped_tokens_escape_gstr_assert (const char *str, + const char *delimiters, + GString *gstring) +{ + g_string_append (gstring, + nm_utils_escaped_tokens_escape_unnecessary (str, delimiters)); } static inline GString * |