PR comments + some more tests.

pull/2533/head
David Garcia Quintas 10 years ago
parent bc78a698b0
commit 96ae8bbba2
  1. 6
      src/core/support/string.c
  2. 7
      test/core/support/string_test.c

@ -173,12 +173,12 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
out_length = 0;
for (i = 0; i < nstrs; i++) {
const size_t slen = strlen(strs[i]);
memcpy(out + out_length, strs[i], slen);
out_length += slen;
if (sep_len > 0 && nstrs > 0 && i < nstrs - 1) {
if (i != 0) {
memcpy(out + out_length, sep, sep_len);
out_length += sep_len;
}
memcpy(out + out_length, strs[i], slen);
out_length += slen;
}
out[out_length] = 0;
if (final_length != NULL) {

@ -176,10 +176,17 @@ static void test_strjoin_sep(void) {
GPR_ASSERT(0 == strcmp("one, two, three, four", joined));
gpr_free(joined);
/* empty separator */
joined = gpr_strjoin_sep(parts, 4, "", &joined_len);
GPR_ASSERT(0 == strcmp("onetwothreefour", joined));
gpr_free(joined);
/* degenerated case specifying zero input parts */
joined = gpr_strjoin_sep(parts, 0, ", ", &joined_len);
GPR_ASSERT(0 == strcmp("", joined));
gpr_free(joined);
/* single part should have no separator */
joined = gpr_strjoin_sep(parts, 1, ", ", &joined_len);
GPR_ASSERT(0 == strcmp("one", joined));
gpr_free(joined);

Loading…
Cancel
Save