From 57867795aa7dead56a7339a13f08ea1f3a5de615 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 22 Jan 2016 16:51:59 +0100 Subject: libsmartcols: support multibyte titles, rename wrap to padding - let's support multibyte table titles - use lib/mbalign.c to align the title - rename title_wrap to title_padding (we already use "wrap" on another places for another things) Signed-off-by: Karel Zak --- lib/mbsalign.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/mbsalign.c') diff --git a/lib/mbsalign.c b/lib/mbsalign.c index 2816cebbf..a9cf84521 100644 --- a/lib/mbsalign.c +++ b/lib/mbsalign.c @@ -315,16 +315,23 @@ done: A pointer to the terminating NUL is returned. */ static char* -mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces) +mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces, int padchar) { /* FIXME: Should we pad with "figure space" (\u2007) if non ascii data present? */ for (/* nothing */; n_spaces && (dest < dest_end); n_spaces--) - *dest++ = ' '; + *dest++ = padchar; *dest = '\0'; return dest; } +size_t +mbsalign (const char *src, char *dest, size_t dest_size, + size_t *width, mbs_align_t align, int flags) +{ + return mbsalign_with_padding(src, dest, dest_size, width, align, flags, ' '); +} + /* Align a string, SRC, in a field of *WIDTH columns, handling multi-byte characters; write the result into the DEST_SIZE-byte buffer, DEST. ALIGNMENT specifies whether to left- or right-justify or to center. @@ -339,8 +346,9 @@ mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces) Update *WIDTH to indicate how many columns were used before padding. */ size_t -mbsalign (const char *src, char *dest, size_t dest_size, - size_t *width, mbs_align_t align, int flags) +mbsalign_with_padding (const char *src, char *dest, size_t dest_size, + size_t *width, mbs_align_t align, int flags, + int padchar) { size_t ret = -1; size_t src_size = strlen (src) + 1; @@ -452,10 +460,10 @@ mbsalign_unibyte: abort(); } - dest = mbs_align_pad (dest, dest_end, start_spaces); + dest = mbs_align_pad (dest, dest_end, start_spaces, padchar); space_left = dest_end - dest; dest = mempcpy (dest, str_to_print, min (n_used_bytes, space_left)); - mbs_align_pad (dest, dest_end, end_spaces); + mbs_align_pad (dest, dest_end, end_spaces, padchar); } #ifdef HAVE_WIDECHAR mbsalign_cleanup: -- cgit v1.2.3-55-g7522