From 9c0eb1700e13c5e72268f7b2cc604a270d005dcc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 21 Mar 2021 14:21:29 +1100 Subject: Cleanup: correct variable name mixup in BLI_str_quoted_substrN Also expand doc-string for `BLI_str_escape_find_quote` --- source/blender/blenlib/intern/string.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index b0d87838d06..3bfedd6f586 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -400,6 +400,11 @@ size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const /** * Find the first un-escaped quote in the string (to find the end of the string). + * + * \param str: Typically this is the first character in a quoted string. + * Where the character before `*str` would be `"`. + + * \return The pointer to the first un-escaped quote. */ const char *BLI_str_escape_find_quote(const char *str) { @@ -436,11 +441,11 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict /* get the end point (i.e. where the next occurrence of " is after the starting point) */ end_match = BLI_str_escape_find_quote(start_match); if (end_match) { - const size_t unescaped_len = (size_t)(end_match - start_match); - char *result = MEM_mallocN(sizeof(char) * (unescaped_len + 1), __func__); - const size_t escaped_len = BLI_str_unescape(result, start_match, unescaped_len); - if (escaped_len != unescaped_len) { - result = MEM_reallocN(result, sizeof(char) * (escaped_len + 1)); + const size_t escaped_len = (size_t)(end_match - start_match); + char *result = MEM_mallocN(sizeof(char) * (escaped_len + 1), __func__); + const size_t unescaped_len = BLI_str_unescape(result, start_match, escaped_len); + if (unescaped_len != escaped_len) { + result = MEM_reallocN(result, sizeof(char) * (unescaped_len + 1)); } return result; } -- cgit v1.2.3