BLI_string: extract quote utility into BLI_str_escape_find_quote

Duplicate logic for this exists in BLI_str_quoted_substrN,
which doesn't properly support escaping.
This commit is contained in:
2020-12-10 15:06:16 +11:00
parent aef9243ebb
commit 2814cdbd86
3 changed files with 24 additions and 13 deletions

View File

@@ -398,6 +398,21 @@ size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const
return len;
}
/**
* Find the first un-escaped quote in the string (to find the end of the string).
*/
const char *BLI_str_escape_find_quote(const char *str)
{
bool escape = false;
while (*str && (*str != '"' || escape)) {
/* A pair of back-slashes represents a single back-slash,
* only use a single back-slash for escaping. */
escape = (escape == false) && (*str == '\\');
str++;
}
return (*str == '"') ? str : NULL;
}
/**
* Makes a copy of the text within the "" that appear after some text 'blahblah'
* i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples"