Add string escaping support for BLI_str_quoted_substrN
authorCampbell Barton <ideasman42@gmail.com>
Thu, 29 May 2014 10:42:09 +0000 (20:42 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 13 Jun 2014 14:47:12 +0000 (00:47 +1000)
source/blender/blenlib/intern/string.c

index 892bb16a5439f975d668d8c735c32594f46d1427..ab81c8fdd4070598cf8d305f0c6657490763169e 100644 (file)
@@ -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);
 }