RNA_property_as_string now escapes the string (so operator redo can include strings with ", \n etc), also fixed a bug in string escape length limit.

This commit is contained in:
2011-08-28 09:28:41 +00:00
parent fa2ba5fbf5
commit 852a03a6af
2 changed files with 13 additions and 6 deletions

View File

@@ -129,7 +129,6 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
while(len < maxlen) {
switch(*src) {
case '\0':
*dst= '\0';
break;
case '\\':
case '"':
@@ -144,7 +143,6 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
}
else {
/* not enough space to escape */
*dst= '\0';
break;
}
/* intentionally pass through */
@@ -156,6 +154,8 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
len++;
}
*dst= '\0';
return len;
}

View File

@@ -2106,7 +2106,7 @@ char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fi
if(length+1 < fixedlen)
buf= fixedbuf;
else
buf= MEM_callocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
buf= MEM_mallocN(sizeof(char)*(length+1), "RNA_string_get_alloc");
RNA_property_string_get(ptr, prop, buf);
@@ -4271,11 +4271,18 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
break;
case PROP_STRING:
{
/* string arrays dont exist */
char *buf_esc;
char *buf;
buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
BLI_dynstr_appendf(dynstr, "\"%s\"", buf);
int length;
length= RNA_property_string_length(ptr, prop);
buf= MEM_mallocN(sizeof(char)*(length+1), "RNA_property_as_string");
buf_esc= MEM_mallocN(sizeof(char)*(length*2+1), "RNA_property_as_string esc");
RNA_property_string_get(ptr, prop, buf);
BLI_strescape(buf_esc, buf, length*2);
MEM_freeN(buf);
BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
MEM_freeN(buf_esc);
break;
}
case PROP_ENUM: