Skip to content

Commit

Permalink
UCS/STRING: Fix ucs_string_buffer_append_array
Browse files Browse the repository at this point in the history
  • Loading branch information
yosefe committed Feb 11, 2025
1 parent 9973007 commit ae2834d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ucs/datastruct/string_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void ucs_string_buffer_translate(ucs_string_buffer_t *strb,
ucs_string_buffer_appendf((_strb), _fmt, (_array)[0]); \
} \
for (_i = 1; _i < (_count); ++_i) { \
ucs_string_buffer_appendf((_strb), _fmt "%s", (_sep), \
ucs_string_buffer_appendf((_strb), "%s" _fmt, (_sep), \
(_array)[_i]); \
} \
}
Expand Down
8 changes: 7 additions & 1 deletion test/gtest/ucs/test_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,18 @@ UCS_TEST_F(test_string_buffer, flags) {
EXPECT_EQ(std::string("one|three"), ucs_string_buffer_cstr(&strb));
}

UCS_TEST_F(test_string_buffer, list) {
UCS_TEST_F(test_string_buffer, array) {
static const char *str_array[] = {"once", "upon", "a", "time"};
UCS_STRING_BUFFER_ONSTACK(strb, 128);
ucs_string_buffer_append_array(&strb, " ", "%s", str_array,
ucs_static_array_size(str_array));
EXPECT_EQ(std::string("once upon a time"), ucs_string_buffer_cstr(&strb));

ucs_string_buffer_reset(&strb);
static int num_array[] = {1, 2, 3, 4};
ucs_string_buffer_append_array(&strb, ",", "%d", num_array,
ucs_static_array_size(num_array));
EXPECT_EQ(std::string("1,2,3,4"), ucs_string_buffer_cstr(&strb));
}

UCS_TEST_F(test_string_buffer, dump) {
Expand Down

0 comments on commit ae2834d

Please sign in to comment.