Browse Source

Added a new function arg_dstr_catc for appending char

types and use it in arg_print_formatted_ds()
pull/37/head
Hrvoje Zeba 5 years ago
parent
commit
070411f5ab
  1. 5
      src/arg_dstr.c
  2. 2
      src/argtable3.c
  3. 1
      src/argtable3.h

5
src/arg_dstr.c

@ -177,6 +177,11 @@ void arg_dstr_cat(arg_dstr_t ds, const char* str) {
strncat(ds->data, str, strlen(str));
}
void arg_dstr_catc(arg_dstr_t ds, char c) {
setup_append_buf(ds, 2);
strncat(ds->data, &c, 1);
}
/*
* The logic of the `arg_dstr_catf` function is adapted from the `bformat`
* function in The Better String Library by Paul Hsieh. Here is the copyright

2
src/argtable3.c

@ -917,7 +917,7 @@ static void arg_print_formatted_ds(arg_dstr_t ds, const unsigned lmargin, const
/* Output line of text */
while (line_start < line_end) {
char c = *(text + line_start);
arg_dstr_cat(ds, &c);
arg_dstr_catc(ds, c);
line_start++;
}
arg_dstr_cat(ds, "\n");

1
src/argtable3.h

@ -243,6 +243,7 @@ ARG_EXTERN void arg_dstr_reset(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_free(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_set(arg_dstr_t ds, char* str, arg_dstr_freefn* free_proc);
ARG_EXTERN void arg_dstr_cat(arg_dstr_t ds, const char* str);
ARG_EXTERN void arg_dstr_catc(arg_dstr_t ds, char c);
ARG_EXTERN void arg_dstr_catf(arg_dstr_t ds, const char* fmt, ...);
ARG_EXTERN char* arg_dstr_cstr(arg_dstr_t ds);

Loading…
Cancel
Save