Add a string ellipsizing utility

Add a function to ellipsize a string to a certain length.

Closes: #2409
Approved by: alexlarsson
This commit is contained in:
Matthias Clasen
2018-12-08 16:11:31 -05:00
committed by Atomic Bot
parent 883de69c09
commit 8d2f76e96e
2 changed files with 23 additions and 0 deletions

View File

@@ -967,3 +967,25 @@ format_timestamp (guint64 timestamp)
return str;
}
char *
ellipsize_string (const char *text, int len)
{
char *ret = g_strdup (text);
char *p;
int i;
if (g_utf8_strlen (ret, -1) > len)
{
p = ret;
for (i = 0; i < len - 3; i++)
p = g_utf8_next_char (p);
p[0] = '.';
p[1] = '.';
p[2] = '.';
p[3] = '\0';
}
return ret;
}

View File

@@ -126,5 +126,6 @@ Column *handle_column_args (Column *all_columns,
GError **error);
char * format_timestamp (guint64 timestamp);
char * ellipsize_string (const char *text, int len);
#endif /* __FLATPAK_BUILTINS_UTILS_H__ */