Rename gpr_strpad as gpr_leftpad

pull/6875/head
Yuchen Zeng 9 years ago
parent bcf5023bb6
commit 289dcb1b68
  1. 8
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  2. 2
      src/core/lib/support/string.c
  3. 2
      src/core/lib/support/string.h
  4. 18
      test/core/support/string_test.c

@ -2024,7 +2024,7 @@ static char *format_flowctl_context_var(const char *context, const char *var,
if (context == NULL) {
*scope = NULL;
gpr_asprintf(&buf, "%s(%" PRId64 ")", var, val);
result = gpr_strpad(buf, ' ', 40);
result = gpr_leftpad(buf, ' ', 40);
gpr_free(buf);
return result;
}
@ -2037,7 +2037,7 @@ static char *format_flowctl_context_var(const char *context, const char *var,
gpr_free(tmp);
}
gpr_asprintf(&buf, "%s.%s(%" PRId64 ")", underscore_pos + 1, var, val);
result = gpr_strpad(buf, ' ', 40);
result = gpr_leftpad(buf, ' ', 40);
gpr_free(buf);
return result;
}
@ -2068,8 +2068,8 @@ void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase,
char *clisvr = is_client ? "client" : "server";
char *prefix;
tmp_phase = gpr_strpad(phase, ' ', 8);
tmp_scope1 = gpr_strpad(scope1, ' ', 11);
tmp_phase = gpr_leftpad(phase, ' ', 8);
tmp_scope1 = gpr_leftpad(scope1, ' ', 11);
gpr_asprintf(&prefix, "FLOW %s: %s %s ", phase, clisvr, scope1);
gpr_free(tmp_phase);
gpr_free(tmp_scope1);

@ -194,7 +194,7 @@ int int64_ttoa(int64_t value, char *string) {
return i;
}
char *gpr_strpad(const char *str, char flag, size_t length) {
char *gpr_leftpad(const char *str, char flag, size_t length) {
const size_t str_length = strlen(str);
const size_t out_length = str_length > length ? str_length : length;
char *out = gpr_malloc(out_length + 1);

@ -85,7 +85,7 @@ void gpr_reverse_bytes(char *str, int len);
/* Pad a string with flag characters. The given length specifies the minimum
field width. The input string is never truncated. */
char *gpr_strpad(const char *str, char flag, size_t length);
char *gpr_leftpad(const char *str, char flag, size_t length);
/* Join a set of strings, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length

@ -334,34 +334,34 @@ static void test_int64toa() {
GPR_ASSERT(0 == strcmp("-9223372036854775808", buf));
}
static void test_strpad() {
static void test_leftpad() {
char *padded;
padded = gpr_strpad("foo", ' ', 5);
padded = gpr_leftpad("foo", ' ', 5);
GPR_ASSERT(0 == strcmp(" foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", ' ', 4);
padded = gpr_leftpad("foo", ' ', 4);
GPR_ASSERT(0 == strcmp(" foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", ' ', 3);
padded = gpr_leftpad("foo", ' ', 3);
GPR_ASSERT(0 == strcmp("foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", ' ', 2);
padded = gpr_leftpad("foo", ' ', 2);
GPR_ASSERT(0 == strcmp("foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", ' ', 1);
padded = gpr_leftpad("foo", ' ', 1);
GPR_ASSERT(0 == strcmp("foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", ' ', 0);
padded = gpr_leftpad("foo", ' ', 0);
GPR_ASSERT(0 == strcmp("foo", padded));
gpr_free(padded);
padded = gpr_strpad("foo", '0', 5);
padded = gpr_leftpad("foo", '0', 5);
GPR_ASSERT(0 == strcmp("00foo", padded));
gpr_free(padded);
}
@ -378,6 +378,6 @@ int main(int argc, char **argv) {
test_strsplit();
test_ltoa();
test_int64toa();
test_strpad();
test_leftpad();
return 0;
}

Loading…
Cancel
Save