aboutsummaryrefslogtreecommitdiffstats
path: root/epan/value_string.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-03-29 23:23:28 +0000
committerEvan Huus <eapache@gmail.com>2013-03-29 23:23:28 +0000
commitd155b0da1965575060da94a1e13558e5bf2d67df (patch)
treeb4d872892f490806d642ca47284f5d71c0ca4987 /epan/value_string.c
parente964ab416434cd0b58cd776cf96a2d0ac7bc6f6d (diff)
Implement str_to_val, opposite of val_to_str for value_strings.
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8467 svn path=/trunk/; revision=48645
Diffstat (limited to 'epan/value_string.c')
-rw-r--r--epan/value_string.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/epan/value_string.c b/epan/value_string.c
index 64eddb7480..b81679be54 100644
--- a/epan/value_string.c
+++ b/epan/value_string.c
@@ -102,6 +102,48 @@ try_val_to_str(const guint32 val, const value_string *vs)
return try_val_to_str_idx(val, vs, &ignore_me);
}
+/* REVERSE VALUE STRING */
+
+/* We use the same struct as for regular value strings, but we look up strings
+ * and return values instead */
+
+/* Like val_to_str except backwards */
+guint32
+str_to_val(const gchar *val, const value_string *vs, const guint32 err_val)
+{
+ gint index;
+
+ index = str_to_val_idx(val, vs);
+
+ if (index >= 0) {
+ return vs[index].value;
+ }
+
+ return err_val;
+}
+
+/* Find the index of a string in a value_string, or -1 when not present */
+gint
+str_to_val_idx(const gchar *val, const value_string *vs)
+{
+ gint i = 0;
+
+ if(vs) {
+
+ while (vs[i].strptr) {
+
+ if (strcmp(vs[i].strptr, val) == 0) {
+ return i;
+ }
+
+ i++;
+ }
+
+ }
+
+ return -1;
+}
+
/* EXTENDED VALUE STRING */
/* Extended value strings allow fast(er) value_string array lookups by