summaryrefslogtreecommitdiffstats
path: root/lib/mbsalign.c
diff options
context:
space:
mode:
authorKarel Zak2016-09-06 10:51:25 +0200
committerKarel Zak2016-09-06 10:51:25 +0200
commitff471d89a12eef331de8e66c33cd9a2c0e23984e (patch)
tree9f2e92f090eb3c6b9ef442abbdd74a75a7776a0d /lib/mbsalign.c
parentlib/randutils: add xsrand() and rand_get_number() (diff)
downloadkernel-qcow2-util-linux-ff471d89a12eef331de8e66c33cd9a2c0e23984e.tar.gz
kernel-qcow2-util-linux-ff471d89a12eef331de8e66c33cd9a2c0e23984e.tar.xz
kernel-qcow2-util-linux-ff471d89a12eef331de8e66c33cd9a2c0e23984e.zip
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 <kzak@redhat.com>
Diffstat (limited to 'lib/mbsalign.c')
-rw-r--r--lib/mbsalign.c12
1 files changed, 9 insertions, 3 deletions
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