summaryrefslogtreecommitdiff
path: root/common/rt/src/rt_string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/rt/src/rt_string.cpp')
-rw-r--r--common/rt/src/rt_string.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/common/rt/src/rt_string.cpp b/common/rt/src/rt_string.cpp
new file mode 100644
index 0000000..bb2ef4c
--- /dev/null
+++ b/common/rt/src/rt_string.cpp
@@ -0,0 +1,35 @@
+#include <stdint.h>
+#include <string.h>
+#include "rt_string.h"
+
+const char *
+try_val_to_str_idx(const unsigned int val, const struct value_string *vs, int *idx)
+{
+ int i = 0;
+ if (idx == NULL){
+ goto finish;
+ }
+
+ if(vs) {
+ while (vs[i].strptr) {
+ if (vs[i].value == val) {
+ *idx = i;
+ return(vs[i].strptr);
+ }
+ i++;
+ }
+ }
+
+finish:
+ *idx = -1;
+ return NULL;
+}
+
+const char*
+val_to_str(const unsigned int val, const struct value_string *vs)
+{
+ int ignore_me;
+
+ return try_val_to_str_idx(val, vs, &ignore_me);
+}
+