diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-04 07:12:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-04 07:14:02 +0300 |
commit | 0baae1837548f5617c11da4acd8a282400b2bd62 (patch) | |
tree | 0919cc0aa61a75d2e7660c23a3dd8e497f4f0b93 /source/blender/blenlib/intern | |
parent | 38ed95fe8d6f4c47c0c5f09ffecc987d75150dcc (diff) |
BLI_string_utils: add BLI_string_join_array_by_sep_char
Utility to join strings into a fixed size buffer.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/string_utils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index 85cb32b6457..a579327c73e 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -435,6 +435,29 @@ char *BLI_string_join_array(char *result, } /** + * A version of #BLI_string_join that takes a separator which can be any character including '\0'. + */ +char *BLI_string_join_array_by_sep_char( + char *result, size_t result_len, char sep, const char *strings[], uint strings_len) +{ + char *c = result; + char *c_end = &result[result_len - 1]; + for (uint i = 0; i < strings_len; i++) { + if (i != 0) { + if (c < c_end) { + *c++ = sep; + } + } + const char *p = strings[i]; + while (*p && (c < c_end)) { + *c++ = *p++; + } + } + *c = '\0'; + return c; +} + +/** * Join an array of strings into a newly allocated, null terminated string. */ char *BLI_string_join_arrayN(const char *strings[], uint strings_len) |