[gedit/wip/swilmet/tepl-step3: 16/22] Utils: use str truncate functions from Tepl
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/swilmet/tepl-step3: 16/22] Utils: use str truncate functions from Tepl
- Date: Thu, 7 Nov 2019 13:50:19 +0000 (UTC)
commit 9d559fcf4eca0a86fef7318f0f3341b1329d518a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Nov 4 15:49:13 2019 +0100
Utils: use str truncate functions from Tepl
This is just a first step, much more can be re-used from Tepl, and Tepl
should be developed alongside gedit, to improve Tepl and reduce the
amount of code from gedit.
gedit/gedit-utils.c | 66 +++--------------------------------------------------
1 file changed, 3 insertions(+), 63 deletions(-)
---
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 10ff52337..6e1f2bf25 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib/gi18n.h>
+#include <tepl/tepl.h>
/* For the workspace/viewport stuff */
#ifdef GDK_WINDOWING_X11
@@ -214,79 +215,18 @@ gedit_warning (GtkWindow *parent, const gchar *format, ...)
gtk_widget_show (dialog);
}
-/* the following functions are taken from eel */
-
-static gchar *
-gedit_utils_str_truncate (const gchar *string,
- guint truncate_length,
- gboolean middle)
-{
- GString *truncated;
- guint length;
- guint n_chars;
- guint num_left_chars;
- guint right_offset;
- guint delimiter_length;
- const gchar *delimiter = "\342\200\246";
-
- g_return_val_if_fail (string != NULL, NULL);
-
- length = strlen (string);
-
- g_return_val_if_fail (g_utf8_validate (string, length, NULL), NULL);
-
- /* It doesnt make sense to truncate strings to less than
- * the size of the delimiter plus 2 characters (one on each
- * side)
- */
- delimiter_length = g_utf8_strlen (delimiter, -1);
- if (truncate_length < (delimiter_length + 2))
- {
- return g_strdup (string);
- }
-
- n_chars = g_utf8_strlen (string, length);
-
- /* Make sure the string is not already small enough. */
- if (n_chars <= truncate_length)
- {
- return g_strdup (string);
- }
-
- /* Find the 'middle' where the truncation will occur. */
- if (middle)
- {
- num_left_chars = (truncate_length - delimiter_length) / 2;
- right_offset = n_chars - truncate_length + num_left_chars + delimiter_length;
-
- truncated = g_string_new_len (string,
- g_utf8_offset_to_pointer (string, num_left_chars) - string);
- g_string_append (truncated, delimiter);
- g_string_append (truncated, g_utf8_offset_to_pointer (string, right_offset));
- }
- else
- {
- num_left_chars = truncate_length - delimiter_length;
- truncated = g_string_new_len (string,
- g_utf8_offset_to_pointer (string, num_left_chars) - string);
- g_string_append (truncated, delimiter);
- }
-
- return g_string_free (truncated, FALSE);
-}
-
gchar *
gedit_utils_str_middle_truncate (const gchar *string,
guint truncate_length)
{
- return gedit_utils_str_truncate (string, truncate_length, TRUE);
+ return tepl_utils_str_middle_truncate (string, truncate_length);
}
gchar *
gedit_utils_str_end_truncate (const gchar *string,
guint truncate_length)
{
- return gedit_utils_str_truncate (string, truncate_length, FALSE);
+ return tepl_utils_str_end_truncate (string, truncate_length);
}
gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]