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.
This commit is contained in:
Campbell Barton 2020-09-01 16:32:11 +10:00
parent 76f513f6dc
commit 87aa13d025
1 changed files with 6 additions and 5 deletions

View File

@ -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;
}