diff options
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -398,6 +398,19 @@ buf_chomp (struct buffer *buf) buf_null_terminate (buf); } +const char * +skip_leading_whitespace (const char *str) +{ + while (*str) + { + const char c = *str; + if (!(c == ' ' || c == '\t')) + break; + ++str; + } + return str; +} + /* * like buf_null_terminate, but operate on strings */ @@ -475,6 +488,42 @@ string_clear (char *str) } /* + * Return the length of a string array + */ +int +string_array_len (const char **array) +{ + int i = 0; + if (array) + { + while (array[i]) + ++i; + } + return i; +} + +char * +print_argv (const char **p, struct gc_arena *gc, const unsigned int flags) +{ + struct buffer out = alloc_buf_gc (256, gc); + int i = 0; + for (;;) + { + const char *cp = *p++; + if (!cp) + break; + if (i) + buf_printf (&out, " "); + if (flags & PA_BRACKET) + buf_printf (&out, "[%s]", cp); + else + buf_printf (&out, "%s", cp); + ++i; + } + return BSTR (&out); +} + +/* * Allocate a string inside a buffer */ struct buffer |