[gedit] Revert "Utils: use str truncate functions from Tepl"
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Revert "Utils: use str truncate functions from Tepl"
- Date: Wed, 6 Nov 2019 19:04:50 +0000 (UTC)
commit bc11b8c95395f6584cb3c407a2e623590ab12fe7
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Nov 6 13:02:56 2019 -0600
Revert "Utils: use str truncate functions from Tepl"
This reverts commit 782eddbf740cf1ae70e34e3dc094315e11c87acc.
gedit/gedit-utils.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 6e1f2bf25..10ff52337 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -24,7 +24,6 @@
#include <string.h>
#include <glib/gi18n.h>
-#include <tepl/tepl.h>
/* For the workspace/viewport stuff */
#ifdef GDK_WINDOWING_X11
@@ -215,18 +214,79 @@ 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 tepl_utils_str_middle_truncate (string, truncate_length);
+ return gedit_utils_str_truncate (string, truncate_length, TRUE);
}
gchar *
gedit_utils_str_end_truncate (const gchar *string,
guint truncate_length)
{
- return tepl_utils_str_end_truncate (string, truncate_length);
+ return gedit_utils_str_truncate (string, truncate_length, FALSE);
}
gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]