aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/unformat.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-11-13 21:43:17 +0000
committerDave Wallace <dwallacelf@gmail.com>2023-11-14 21:32:22 +0000
commitf6f21db2e30b83236464887df62f50a189bbb859 (patch)
tree51d326b79947e7672de598c0d00993150a2d2ae0 /src/vppinfra/unformat.c
parent1b86f0f477692731edaf4da99f3b639c63bbd8d0 (diff)
vppinfra: add unformat_{single,double}_quoted_string function
Change-Id: I8ee90be1b772074c1130b98c71b3be48c973b2e2 Type: improvement Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/unformat.c')
-rw-r--r--src/vppinfra/unformat.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c
index cea5b677dec..fe1a46e4a12 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -1143,6 +1143,46 @@ unformat_c_string_array (unformat_input_t *input, va_list *va)
return rv;
}
+static uword
+__unformat_quoted_string (unformat_input_t *input, u8 **sp, char quote)
+{
+ u8 *s = 0;
+ uword c, p = 0;
+
+ while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
+ if (!is_white_space (c))
+ break;
+
+ if (c != quote)
+ return 0;
+
+ while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
+ {
+ if (c == quote && p != '\\')
+ {
+ *sp = s;
+ return 1;
+ }
+ vec_add1 (s, c);
+ p = c;
+ }
+ vec_free (s);
+
+ return 0;
+}
+
+__clib_export uword
+unformat_single_quoted_string (unformat_input_t *input, va_list *va)
+{
+ return __unformat_quoted_string (input, va_arg (*va, u8 **), '\'');
+}
+
+__clib_export uword
+unformat_double_quoted_string (unformat_input_t *input, va_list *va)
+{
+ return __unformat_quoted_string (input, va_arg (*va, u8 **), '"');
+}
+
#endif /* CLIB_UNIX */