extern int scols_table_is_nowrap(const struct libscols_table *tb);
extern int scols_table_is_nolinesep(const struct libscols_table *tb);
extern int scols_table_is_tree(const struct libscols_table *tb);
+extern int scols_table_is_noencoding(const struct libscols_table *tb);
extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable);
extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable);
+extern int scols_table_enable_noencoding(struct libscols_table *tb, int enable);
extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep);
extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep);
return tb->no_wrap;
}
+/**
+ * scols_table_enable_noencoding:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * The library encode non-printable and control chars by \x<hex> by default.
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ *
+ * Since: 2.31
+ */
+int scols_table_enable_noencoding(struct libscols_table *tb, int enable)
+{
+ if (!tb)
+ return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "encoding: %s", enable ? "ENABLE" : "DISABLE"));
+ tb->no_encode = enable ? 1 : 0;
+ return 0;
+}
+
+/**
+ * scols_table_is_noencoding:
+ * @tb: a pointer to a struct libscols_table instance
+ *
+ * Returns: 1 if encoding is disabled.
+ *
+ * Since: 2.31
+ */
+int scols_table_is_noencoding(const struct libscols_table *tb)
+{
+ return tb->no_encode;
+}
+
/**
* scols_table_colors_wanted:
* @tb: table
}
/* encode data by mbs_safe_encode() to avoid control and non-printable chars */
-static char *buffer_get_safe_data(struct libscols_buffer *buf, size_t *cells,
+static char *buffer_get_safe_data(struct libscols_table *tb,
+ struct libscols_buffer *buf,
+ size_t *cells,
const char *safechars)
{
char *data = buffer_get_data(buf);
goto nothing;
}
- res = mbs_safe_encode_to_buffer(data, cells, buf->encdata, safechars);
+ if (tb->no_encode) {
+ *cells = mbs_safe_width(data);
+ strcpy(buf->encdata, data);
+ res = buf->encdata;
+ } else {
+ res = mbs_safe_encode_to_buffer(data, cells, buf->encdata, safechars);
+ }
+
if (!res || !*cells || *cells == (size_t) -1)
goto nothing;
return res;
line_ascii_art_to_buffer(tb, ln, art);
if (!list_empty(&ln->ln_branch) && has_pending_data(tb))
buffer_append_data(art, vertical_symbol(tb));
- data = buffer_get_safe_data(art, &len_pad, NULL);
+ data = buffer_get_safe_data(tb, art, &len_pad, NULL);
if (data && len_pad)
fputs(data, tb->out);
free_buffer(art);
/* Encode. Note that 'len' and 'width' are number of cells, not bytes.
*/
- data = buffer_get_safe_data(buf, &len, scols_column_get_safechars(cl));
+ data = buffer_get_safe_data(tb, buf, &len, scols_column_get_safechars(cl));
if (!data)
data = "";
bytes = strlen(data);
DBG(TAB, ul_debugobj(tb, "printing title"));
/* encode data */
- bufsz = mbs_safe_encode_size(strlen(tb->title.data)) + 1;
- if (bufsz == 1) {
- DBG(TAB, ul_debugobj(tb, "title is empty string -- ignore"));
- return 0;
- }
- buf = malloc(bufsz);
- if (!buf) {
- rc = -ENOMEM;
- goto done;
- }
+ if (tb->no_encode) {
+ bufsz = strlen(tb->title.data) + 1;
+ buf = strdup(tb->title.data);
+ if (!buf) {
+ rc = -ENOMEM;
+ goto done;
+ }
+ } else {
+ bufsz = mbs_safe_encode_size(strlen(tb->title.data)) + 1;
+ if (bufsz == 1) {
+ DBG(TAB, ul_debugobj(tb, "title is empty string -- ignore"));
+ return 0;
+ }
+ buf = malloc(bufsz);
+ if (!buf) {
+ rc = -ENOMEM;
+ goto done;
+ }
- if (!mbs_safe_encode_to_buffer(tb->title.data, &bufsz, buf, NULL) ||
- !bufsz || bufsz == (size_t) -1) {
- rc = -EINVAL;
- goto done;
+ if (!mbs_safe_encode_to_buffer(tb->title.data, &bufsz, buf, NULL) ||
+ !bufsz || bufsz == (size_t) -1) {
+ rc = -EINVAL;
+ goto done;
+ }
}
/* truncate and align */