From 87aa13d025797f2f73f6b6216422843d042c4453 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 1 Sep 2020 16:32:11 +1000 Subject: 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. --- source/blender/python/intern/bpy_capi_utils.c | 11 ++++++----- 1 file 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; } -- cgit v1.2.3