From c7fa7407b02c593b79492a2c57369af10032ec0d Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 13 Dec 2003 22:29:00 +0000 Subject: Convert control chars to blanks. 2003-12-13 Christian Persch * lib/ephy-string.c: (ephy_string_shorten), (ephy_string_to_int), (ephy_string_blank_chr), (ephy_string_elide_underscores), (ephy_string_double_underscores): * lib/ephy-string.h: * src/ephy-tab.c: (ephy_tab_set_link_message): Convert control chars to blanks. --- lib/ephy-string.c | 50 +++++++++++++++++++++++++++----------------------- lib/ephy-string.h | 9 ++++----- 2 files changed, 31 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/ephy-string.c b/lib/ephy-string.c index 1c4ff358d..a2882c685 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -17,7 +17,7 @@ */ #ifdef HAVE_CONFIG_H -#include +#include "config.h" #endif #include "ephy-string.h" @@ -39,9 +39,9 @@ * it can still split a sequence of combining characters */ char * -ephy_string_shorten (const gchar *str, gint target_length) +ephy_string_shorten (const char *str, int target_length) { - gchar *new_str; + char *new_str; glong actual_length; gulong bytes; @@ -71,7 +71,8 @@ ephy_string_to_int (const char *string, gulong *integer) char *parse_end; /* Check for the case of an empty string. */ - if (string == NULL || *string == '\0') { + if (string == NULL || *string == '\0') + { return FALSE; } @@ -80,13 +81,16 @@ ephy_string_to_int (const char *string, gulong *integer) result = strtol (string, &parse_end, 0); /* Check that the result is in range. */ - if ((result == G_MINLONG || result == G_MAXLONG) && errno == ERANGE) { + if ((result == G_MINLONG || result == G_MAXLONG) && errno == ERANGE) + { return FALSE; } /* Check that all the trailing characters are spaces. */ - while (*parse_end != '\0') { - if (!g_ascii_isspace (*parse_end++)) { + while (*parse_end != '\0') + { + if (!g_ascii_isspace (*parse_end++)) + { return FALSE; } } @@ -107,33 +111,34 @@ ephy_string_to_int (const char *string, gulong *integer) * of @remove_this. */ char * -ephy_string_strip_chr (const char *source, char remove_this) +ephy_string_blank_chr (char *source) { - char *result, *out; - const char *in; + char *p; - if (source == NULL) { + if (source == NULL) + { return NULL; } - result = g_new (char, strlen (source) + 1); - in = source; - out = result; - do { - if (*in != remove_this) { - *out++ = *in; + p = source; + while (*p != '\0') + { + if ((guchar) *p < 0x20) + { + *p = ' '; } - } while (*in++ != '\0'); + p++; + } - return result; + return source; } /* copied from egg-toolbar-editor.c */ char * -ephy_string_elide_underscores (const gchar *original) +ephy_string_elide_underscores (const char *original) { - gchar *q, *result; - const gchar *p; + char *q, *result; + const char *p; gboolean last_underscore; q = result = g_malloc (strlen (original) + 1); @@ -194,4 +199,3 @@ ephy_string_double_underscores (const char *string) return escaped; } - diff --git a/lib/ephy-string.h b/lib/ephy-string.h index 6cfbd892f..f2907219f 100644 --- a/lib/ephy-string.h +++ b/lib/ephy-string.h @@ -28,13 +28,12 @@ G_BEGIN_DECLS gboolean ephy_string_to_int (const char *string, gulong *integer); -char *ephy_string_strip_chr (const char *source, - char remove_this); +char *ephy_string_blank_chr (char *source); -char *ephy_string_shorten (const gchar *str, - gint target_length); +char *ephy_string_shorten (const char *str, + int target_length); -char *ephy_string_elide_underscores (const gchar *original); +char *ephy_string_elide_underscores (const char *original); char *ephy_string_double_underscores (const char *string); -- cgit v1.2.3