1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 11:13:12 +02:00

core: add a way to count the suffix length in max chars displayed in cut of string ("cut:" and "cutscr:") (closes #963)

The format to use is one of:

- ${cut:+max,suffix,string}
- ${cutscr:+max,suffix,string}

With the "+" before max, WeeChat ensures there are at most "max" chars in
output, including the length of suffix string.
This commit is contained in:
Sébastien Helleu
2017-04-24 22:37:49 +02:00
parent 0470a71af9
commit 112bebcddf
28 changed files with 331 additions and 195 deletions
+8 -1
View File
@@ -326,6 +326,7 @@ eval_replace_vars_cb (void *data, const char *text)
struct t_hdata *hdata;
void *pointer;
int i, length_hide_char, length, index, rc, extra_vars_eval, screen;
int count_suffix;
long number;
long unsigned int ptr;
time_t date;
@@ -436,6 +437,12 @@ eval_replace_vars_cb (void *data, const char *text)
pos = strchr (text + length, ',');
if (!pos)
return strdup ("");
count_suffix = 0;
if (text[length] == '+')
{
length++;
count_suffix = 1;
}
pos2 = strchr (pos + 1, ',');
if (!pos2)
return strdup ("");
@@ -452,7 +459,7 @@ eval_replace_vars_cb (void *data, const char *text)
tmp = strndup (pos + 1, pos2 - pos - 1);
if (!tmp)
return strdup ("");
value = string_cut (pos2 + 1, number, screen, tmp);
value = string_cut (pos2 + 1, number, count_suffix, screen, tmp);
free (tmp);
return value;
}