summaryrefslogtreecommitdiff
path: root/lib/frrstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/frrstr.c')
-rw-r--r--lib/frrstr.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/frrstr.c b/lib/frrstr.c
index bb112afef7..1e743d4b0c 100644
--- a/lib/frrstr.c
+++ b/lib/frrstr.c
@@ -249,3 +249,24 @@ const char *frrstr_skip_over_char(const char *s, int skipc)
}
return NULL;
}
+
+/*
+ * Advance backward in string until reaching the char `toc`
+ * if beginning of string is reached w/o finding char return NULL
+ *
+ * /foo/bar'baz/booz'/foo
+ */
+const char *frrstr_back_to_char(const char *s, int toc)
+{
+ const char *next = s;
+ const char *prev = NULL;
+
+ if (s[0] == 0)
+ return NULL;
+ if (!strpbrk(s, "'\"\\"))
+ return strrchr(s, toc);
+ while ((next = frrstr_skip_over_char(next, toc)))
+ prev = next - 1;
+ return prev;
+}
+