diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-01 09:32:11 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-01 09:32:11 +0300 |
commit | 87aa13d025797f2f73f6b6216422843d042c4453 (patch) | |
tree | 50bb47a4fed8bc830afeaf9a94cc58484c09c748 /source/blender/python | |
parent | 76f513f6dcc352c62944858123d91dc393a55650 (diff) |
PyAPI: prevent leading comma when printing some enums
BPy_enum_as_string (used for creating error messages)
showed a leading comma for enums that used category headings.
While harmless, it looks odd.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_capi_utils.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_capi_utils.c b/source/blender/python/intern/bpy_capi_utils.c index 27eea80f1f6..8eb44e918d7 100644 --- a/source/blender/python/intern/bpy_capi_utils.c +++ b/source/blender/python/intern/bpy_capi_utils.c @@ -51,16 +51,17 @@ void BPy_SetContext(bContext *C) char *BPy_enum_as_string(const EnumPropertyItem *item) { DynStr *dynstr = BLI_dynstr_new(); - const EnumPropertyItem *e; - char *cstring; - for (e = item; item->identifier; item++) { + /* We can't compare with the first element in the array + * since it may be a category (without an identifier). */ + for (bool is_first = true; item->identifier; item++) { if (item->identifier[0]) { - BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier); + BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier); + is_first = false; } } - cstring = BLI_dynstr_get_cstring(dynstr); + char *cstring = BLI_dynstr_get_cstring(dynstr); BLI_dynstr_free(dynstr); return cstring; } |