summaryrefslogtreecommitdiffstats
path: root/lib/mbsalign.c
diff options
context:
space:
mode:
authorKarel Zak2016-01-22 16:51:59 +0100
committerKarel Zak2016-01-22 16:51:59 +0100
commit57867795aa7dead56a7339a13f08ea1f3a5de615 (patch)
treea1b1f247bcb0c70cc135efd98c43c28b0b0234f5 /lib/mbsalign.c
parentlibsmartcols: add title to the test application (diff)
downloadkernel-qcow2-util-linux-57867795aa7dead56a7339a13f08ea1f3a5de615.tar.gz
kernel-qcow2-util-linux-57867795aa7dead56a7339a13f08ea1f3a5de615.tar.xz
kernel-qcow2-util-linux-57867795aa7dead56a7339a13f08ea1f3a5de615.zip
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 <kzak@redhat.com>
Diffstat (limited to 'lib/mbsalign.c')
-rw-r--r--lib/mbsalign.c20
1 files changed, 14 insertions, 6 deletions
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: