Revision: 39655
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39655
Author:   campbellbarton
Date:     2011-08-23 15:08:54 +0000 (Tue, 23 Aug 2011)
Log Message:
-----------
BLI_strescape for a basic, python like string escaping, currently only use for 
drag and drop ID's into the console but should eventually be used for the 
animsys too.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_string.h
    trunk/blender/source/blender/blenlib/intern/string.c
    trunk/blender/source/blender/editors/space_console/space_console.c

Modified: trunk/blender/source/blender/blenlib/BLI_string.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string.h   2011-08-23 13:25:00 UTC 
(rev 39654)
+++ trunk/blender/source/blender/blenlib/BLI_string.h   2011-08-23 15:08:54 UTC 
(rev 39655)
@@ -122,6 +122,8 @@
 #endif
 ;
 
+size_t BLI_strescape(char *dst, const char *src, const size_t maxlen);
+
        /**
         * Compare two strings without regard to case.
         * 

Modified: trunk/blender/source/blender/blenlib/intern/string.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string.c        2011-08-23 
13:25:00 UTC (rev 39654)
+++ trunk/blender/source/blender/blenlib/intern/string.c        2011-08-23 
15:08:54 UTC (rev 39655)
@@ -117,6 +117,49 @@
        return n;
 }
 
+
+/* match pythons string escaping, assume double quotes - (")
+ * TODO: should be used to create RNA animation paths.
+ * TODO: support more fancy string escaping. current code is primitive
+ *    this basically is an ascii version of PyUnicode_EncodeUnicodeEscape()
+ *    which is a useful reference. */
+size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
+{
+       size_t len= 0;
+       while(len < maxlen) {
+               switch(*src) {
+                       case '\0':
+                               *dst= '\0';
+                               break;
+                       case '\\':
+                       case '"':
+
+                               /* less common but should also be support */
+                       case '\t':
+                       case '\n':
+                       case '\r':
+                               if(len + 1 <  maxlen) {
+                                       *dst++ = '\\';
+                                       len++;
+                               }
+                               else {
+                                       /* not enough space to escape */
+                                       *dst= '\0';
+                                       break;
+                               }
+                               /* intentionally pass through */
+                       default:
+                               *dst = *src;
+               }
+               dst++;
+               src++;
+               len++;
+       }
+
+       return len;
+}
+
+
 /* 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"
  * 

Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c  
2011-08-23 13:25:00 UTC (rev 39654)
+++ trunk/blender/source/blender/editors/space_console/space_console.c  
2011-08-23 15:08:54 UTC (rev 39655)
@@ -165,9 +165,12 @@
 {
        char text[64];
        ID *id= drag->poin;
+       char id_esc[(sizeof(id->name) - 2) * 2];
 
-       snprintf(text, sizeof(text), "bpy.data.%s['%s']", 
BKE_idcode_to_name_plural(GS(id->name)), id->name+2); 
+       BLI_strescape(id_esc, id->name+2, sizeof(id_esc));
 
+       snprintf(text, sizeof(text), "bpy.data.%s[\"%s\"]", 
BKE_idcode_to_name_plural(GS(id->name)), id_esc);
+
        /* copy drag path to properties */
        RNA_string_set(drop->ptr, "text", text);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to