diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-18 01:35:38 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-23 20:52:01 +0000 |
| commit | 90cf59eccfd41846fc0fa03a6d5a010a91b46b86 (patch) | |
| tree | 870aca85c70e3d73dd2cca8162be4ac301e22ff5 /lib/frrstr.c | |
| parent | 528628cb2ea4f5a522bf1f6d5b702bb188c4e30e (diff) | |
lib: replace begins_with, add frrstr_endswith
* Change 'begins_with' to 'frrstr_startswith' for consistency
* Add suffix checker, frrstr_endswith()
* Update vtysh to use the new function
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/frrstr.c')
| -rw-r--r-- | lib/frrstr.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/frrstr.c b/lib/frrstr.c index fbbc890ec6..c575c0b568 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -178,7 +178,7 @@ char *frrstr_replace(const char *str, const char *find, const char *replace) return nustr; } -bool begins_with(const char *str, const char *prefix) +bool frrstr_startswith(const char *str, const char *prefix) { if (!str || !prefix) return false; @@ -192,6 +192,20 @@ bool begins_with(const char *str, const char *prefix) return strncmp(str, prefix, lenprefix) == 0; } +bool frrstr_endswith(const char *str, const char *suffix) +{ + if (!str || !suffix) + return false; + + size_t lenstr = strlen(str); + size_t lensuffix = strlen(suffix); + + if (lensuffix > lenstr) + return false; + + return strncmp(&str[lenstr - lensuffix], suffix, lensuffix) == 0; +} + int all_digit(const char *str) { for (; *str != '\0'; str++) |
