Change ws_strdup_escape_underscore() function to be more general, by

accepting any character as the escaped character.  Change existing
uses to use '_' for the underscore escaping.


svn path=/trunk/; revision=36627
This commit is contained in:
Stephen Fisher 2011-04-13 16:56:24 +00:00
parent 763603d3b6
commit 9246c41703
3 changed files with 23 additions and 21 deletions

View File

@ -1015,11 +1015,11 @@ IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len)
}
/*
* This function takes a string and copies it, inserting an underscore before
* every underscore in it.
* This function takes a string and copies it, inserting a 'chr' before
* every 'chr' in it.
*/
gchar*
ws_strdup_escape_underscore (const gchar *str)
ws_strdup_escape_char (const gchar *str, const gchar chr)
{
gchar *p, *q, *new_str;
@ -1027,13 +1027,13 @@ ws_strdup_escape_underscore (const gchar *str)
return NULL;
p = (gchar *)str;
/* Worst case: A string that is full of underscores */
/* Worst case: A string that is full of 'chr' */
q = new_str = g_malloc (strlen(str) * 2 + 1);
while(*p != 0)
{
if(*p == '_')
*q++ = '_';
if(*p == chr)
*q++ = chr;
*q++ = *p++;
}
@ -1044,10 +1044,10 @@ ws_strdup_escape_underscore (const gchar *str)
/*
* This function takes a string and copies it, removing any occurences of double
* underscores with a single underscore.
* 'chr' with a single 'chr'.
*/
gchar*
ws_strdup_unescape_underscore (const gchar *str)
ws_strdup_unescape_char (const gchar *str, const char chr)
{
gchar *p, *q, *new_str;
@ -1055,13 +1055,13 @@ ws_strdup_unescape_underscore (const gchar *str)
return NULL;
p = (gchar *)str;
/* Worst case: A string that contains no underscores */
/* Worst case: A string that contains no 'chr' */
q = new_str = g_malloc (strlen(str) + 1);
while(*p != 0)
{
*q++ = *p;
if ((*p == '_') && (*(p+1) == '_'))
if ((*p == chr) && (*(p+1) == chr))
p += 2;
else
p++;

View File

@ -239,21 +239,23 @@ char * escape_string(char *dst, const char *string);
void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
/** Copy a string, escaping the underscores in it
/** Copy a string, escaping the 'chr' characters in it
*
* @param str The string to be copied
* @return A copy of the string with every original underscore being
* transformed into double underscores.
* @param char The character to be escaped
* @return A copy of the string with every original 'chr' being
* transformed into double 'chr'.
*/
gchar* ws_strdup_escape_underscore (const gchar *str);
gchar* ws_strdup_escape_char (const gchar *str, const gchar chr);
/** Copy a string, unescaping the underscores in it
/** Copy a string, unescaping the 'chr' characters in it
*
* @param str The string to be copied
* @return A copy of the string with every occurence of double underscores in
* the original string being copied as a single underscore.
* @param char The character to be escaped
* @return A copy of the string with every occurence of double 'chr' in
* the original string being copied as a single 'chr'.
*/
gchar* ws_strdup_unescape_underscore (const gchar *str);
gchar* ws_strdup_unescape_char (const gchar *str, const gchar chr);
/** Replace values in a string
*

View File

@ -237,7 +237,7 @@ col_title_change_ok (GtkWidget *w, gpointer parent_w)
occurrence_text = gtk_entry_get_text(GTK_ENTRY(g_object_get_data (G_OBJECT(w), COL_EDIT_OCCURRENCE_TE)));
occurrence = (gint)strtol(occurrence_text, NULL, 10);
escaped_title = ws_strdup_escape_underscore(title);
escaped_title = ws_strdup_escape_char(title, '_');
gtk_tree_view_column_set_title(col, escaped_title);
g_free(escaped_title);
@ -317,7 +317,7 @@ static void
col_details_edit_dlg (gint col_id, GtkTreeViewColumn *col)
{
const gchar *title = gtk_tree_view_column_get_title(col);
gchar *unescaped_title = ws_strdup_unescape_underscore(title);
gchar *unescaped_title = ws_strdup_unescape_char(title, '_');
GtkWidget *label, *field_lb, *occurrence_lb;
GtkWidget *title_te, *format_cmb, *field_te, *occurrence_te;
@ -790,7 +790,7 @@ create_view_and_model(void)
} else {
tooltip_text = g_strdup(col_format_desc(cfile.cinfo.col_fmt[i]));
}
escaped_title = ws_strdup_escape_underscore(cfile.cinfo.col_title[i]);
escaped_title = ws_strdup_escape_char(cfile.cinfo.col_title[i], '_');
gtk_tree_view_column_set_title(col, escaped_title);
g_free (escaped_title);
gtk_tree_view_column_set_clickable(col, TRUE);