diff options
| author | Christian Hopps <chopps@labn.net> | 2023-10-10 04:28:07 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2023-12-28 17:52:57 +0000 |
| commit | d58653a5ba004f1d55981e8a69bcbdb82b87d354 (patch) | |
| tree | cc2a9b89a05ff8a2fc790dc7bf53700e4237a9ef /lib/frrstr.c | |
| parent | db0211d48a78730cd93b0610888f35120e0c7afe (diff) | |
lib: northbound: improve xpath functionality
Allow user to leave keys off of a list entry node at the end of the xpath. This
will return all list entries. Previously there was no way to just get the list
entries. One had to leave off the last list entry node which would then return
all list nodes as well as all the siblings at the same level.
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/frrstr.c')
| -rw-r--r-- | lib/frrstr.c | 21 |
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; +} + |
