aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-11-08 20:09:54 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-11-08 20:09:54 +0000
commitb3a4b56ae94f554adc04c13c13712d4a476f0bbc (patch)
tree7ac01b871f27f512657aeddbae461b08a1584665 /epan
parentad0a9f4b664c411d5f6d4cc5f5dfdbace0d53918 (diff)
Use escape_string*() functions in ftype-string.
Found in attachment #11961, by Didier Gautheron svn path=/trunk/; revision=53174
Diffstat (limited to 'epan')
-rw-r--r--epan/ftypes/ftype-string.c68
1 files changed, 12 insertions, 56 deletions
diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c
index dada9a7169..db0c627960 100644
--- a/epan/ftypes/ftype-string.c
+++ b/epan/ftypes/ftype-string.c
@@ -30,6 +30,7 @@
#define CMP_MATCHES cmp_matches
#include <ctype.h>
+#include <strutil.h>
static void
string_fvalue_new(fvalue_t *fv)
@@ -60,32 +61,12 @@ string_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
static int
string_repr_len(fvalue_t *fv, ftrepr_t rtype)
{
- gchar *p, c;
- int repr_len;
-
switch (rtype) {
case FTREPR_DISPLAY:
return (int)strlen(fv->value.string);
+
case FTREPR_DFILTER:
- repr_len = 0;
- for (p = fv->value.string; (c = *p) != '\0'; p++) {
- /* Backslashes and double-quotes must
- * be escaped */
- if (c == '\\' || c == '"') {
- repr_len += 2;
- }
- /* Values that can't nicely be represented
- * in ASCII need to be escaped. */
- else if (!isprint((unsigned char)c)) {
- /* c --> \xNN */
- repr_len += 4;
- }
- /* Other characters are just passed through. */
- else {
- repr_len++;
- }
- }
- return repr_len + 2; /* string plus leading and trailing quotes */
+ return escape_string_len(fv->value.string);
}
g_assert_not_reached();
return -1;
@@ -94,41 +75,16 @@ string_repr_len(fvalue_t *fv, ftrepr_t rtype)
static void
string_to_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
{
- gchar *p, c;
- char *bufp;
- char hex[3];
-
- if (rtype == FTREPR_DFILTER) {
- bufp = buf;
- *bufp++ = '"';
- for (p = fv->value.string; (c = *p) != '\0'; p++) {
- /* Backslashes and double-quotes must
- * be escaped. */
- if (c == '\\' || c == '"') {
- *bufp++ = '\\';
- *bufp++ = c;
- }
- /* Values that can't nicely be represented
- * in ASCII need to be escaped. */
- else if (!isprint((unsigned char)c)) {
- /* c --> \xNN */
- g_snprintf(hex, sizeof(hex), "%02x", (unsigned char) c);
- *bufp++ = '\\';
- *bufp++ = 'x';
- *bufp++ = hex[0];
- *bufp++ = hex[1];
- }
- /* Other characters are just passed through. */
- else {
- *bufp++ = c;
- }
- }
- *bufp++ = '"';
- *bufp = '\0';
- }
- else {
- strcpy(buf, fv->value.string);
+ switch (rtype) {
+ case FTREPR_DISPLAY:
+ strcpy(buf, fv->value.string);
+ return;
+
+ case FTREPR_DFILTER:
+ escape_string(buf, fv->value.string);
+ return;
}
+ g_assert_not_reached();
}