diff options
Diffstat (limited to 'epan/strutil.c')
-rw-r--r-- | epan/strutil.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/epan/strutil.c b/epan/strutil.c index b2a77f54c7..f6b9b9e4d7 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -1077,3 +1077,59 @@ IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len) return; } +/* + * This function takes a string and copies it, inserting an underscore before + * every underscore in it. + */ +gchar* +ws_strdup_escape_underscore (const gchar *str) +{ + gchar *p, *q, *new_str; + + if(!str) + return NULL; + + p = (gchar *)str; + /* Worst case: A string that is full of underscores */ + q = new_str = g_malloc (strlen(str) * 2 + 1); + + while(*p != 0) + { + if(*p == '_') + *q++ = '_'; + + *q++ = *p++; + } + *q++ = '\0'; + + return new_str; +} + +/* + * This function takes a string and copies it, removing any occurences of double + * underscores with a single underscore. + */ +gchar* +ws_strdup_unescape_underscore (const gchar *str) +{ + gchar *p, *q, *new_str; + + if(!str) + return NULL; + + p = (gchar *)str; + /* Worst case: A string that contains no underscores */ + q = new_str = g_malloc (strlen(str) + 1); + + while(*p != 0) + { + *q++ = *p; + if ((*p == '_') && (*(p+1) == '_')) + p += 2; + else + p++; + } + *q++ = '\0'; + + return new_str; +} |