Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-12-10 07:06:16 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-12-10 07:06:16 +0300
commit2814cdbd86389516eeea570ae12f7c2c7338d81b (patch)
tree6e8ec57790ba650c92a2212ebd3189d800e2230e /source/blender/blenlib/intern
parentaef9243ebb4f3d97d4d9f0eb731250a8c6c1db28 (diff)
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.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/string.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index c4b51338360..d02241230de 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -399,6 +399,21 @@ 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).
+ */
+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"
*