HomeClusterLabs Projects

Refactor: libcrmcommon: make pcmk__add_word() more flexible

Description

Refactor: libcrmcommon: make pcmk__add_word() more flexible

... so we can use it in more situations. Previously it was used like:

char *pcmk__add_word(char *list, const char *word);

list = pcmk__add_word(list, word);

It would calculate the existing length of list every call, and it would always
add a space before word (meaning the list started with a space). Now:

pcmk__add_word(char **list, size_t *len, const char *word);

pcmk__add_word(&list, &len, word);
pcmk__add_word(&list, NULL, word);

If len is provided, it will use that rather than calculate the existing list
length; if len is NULL, it calculates the length as before. This allows for
more efficient building of a long string, when practical, while still allowing
the lazier method if it's not practical to track the length.

It will now add a space before word only if it is not the first thing in the
list.

All callers have been updated accordingly. Their output has been modified to be
unchanged in most cases, although the leading space was not added back for one
log message that previously would end up with two spaces.

Also, pcmkadd_word() is now a wrapper for a new, more general function,
pcmk
add_separated_word(), that allows any string to be specified as the
separator between items in the list.

Details

Provenance
kgaillotAuthored on Oct 1 2020, 1:35 PM
Parents
rPb43a65100284: Refactor: libcrmcommon: simplify logging functions
Branches
Unknown
Tags
Unknown

Event Timeline