From ff471d89a12eef331de8e66c33cd9a2c0e23984e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 6 Sep 2016 10:51:25 +0200 Subject: libsmartcols: support multi-line cells based on line breaks Now libsmartcols completely control when and how wrap long lines/cells. This is sometimes user unfriendly and it would be nice to support multi-line cells where wrap is based on \n (new line char). This patch add new column flag SCOLS_FL_WRAPNL. Signed-off-by: Karel Zak --- lib/mbsalign.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/mbsalign.c') diff --git a/lib/mbsalign.c b/lib/mbsalign.c index 5c21ddeb4..c017ed1b3 100644 --- a/lib/mbsalign.c +++ b/lib/mbsalign.c @@ -107,12 +107,13 @@ size_t mbs_safe_width(const char *s) /* * Copy @s to @buf and replace control and non-printable chars with - * \x?? hex sequence. The @width returns number of cells. + * \x?? hex sequence. The @width returns number of cells. The @safechars + * are not encoded. * * The @buf has to be big enough to store mbs_safe_encode_size(strlen(s))) * bytes. */ -char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf) +char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf, const char *safechars) { const char *p = s; char *r; @@ -129,6 +130,11 @@ char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf) *width = 0; while (p && *p) { + if (safechars && strchr(safechars, *p)) { + *r++ = *p++; + continue; + } + if (iscntrl((unsigned char) *p)) { sprintf(r, "\\x%02x", (unsigned char) *p); r += 4; @@ -208,7 +214,7 @@ char *mbs_safe_encode(const char *s, size_t *width) if (!buf) return NULL; - return mbs_safe_encode_to_buffer(s, width, buf); + return mbs_safe_encode_to_buffer(s, width, buf, NULL); } #ifdef HAVE_WIDECHAR -- cgit v1.2.3-55-g7522