diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-05-29 14:42:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-06-13 18:47:12 +0400 |
commit | 341fd67fbf0f83eaf91dae36508c54e53e097360 (patch) | |
tree | 8550b8c97343f0fdc52dea3d1531162104161543 /source/blender/blenlib/intern/string.c | |
parent | 9db947df41204b3b19e649a54669655642402300 (diff) |
Add string escaping support for BLI_str_quoted_substrN
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r-- | source/blender/blenlib/intern/string.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 892bb16a543..ab81c8fdd40 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -295,11 +295,21 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict startMatch = strstr(str, prefix) + prefixLen + 1; if (startMatch) { /* get the end point (i.e. where the next occurance of " is after the starting point) */ - endMatch = strchr(startMatch, '"'); /* " NOTE: this comment here is just so that my text editor still shows the functions ok... */ - - if (endMatch) + + endMatch = startMatch; + while ((endMatch = strchr(endMatch, '"'))) { + if (LIKELY(*(endMatch - 1) != '\\')) { + break; + } + else { + endMatch++; + } + } + + if (endMatch) { /* return the slice indicated */ return BLI_strdupn(startMatch, (size_t)(endMatch - startMatch)); + } } return BLI_strdupn("", 0); } |