Commit bc11b8c9 authored by Michael Catanzaro's avatar Michael Catanzaro

Revert "Utils: use str truncate functions from Tepl"

This reverts commit 782eddbf.
parent e0bfb14e
......@@ -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 *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment