]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/frrstr.h
Merge pull request #6279 from opensourcerouting/nb-cb-args
[mirror_frr.git] / lib / frrstr.h
index 891a3f337ca98da88542c7392dfd2218dc3d0fab..441d7b86703c0839b27d1301830988c8c1e83454 100644 (file)
 #define _FRRSTR_H_
 
 #include <sys/types.h>
+#include <sys/types.h>
+#ifdef HAVE_LIBPCREPOSIX
+#include <pcreposix.h>
+#else
 #include <regex.h>
+#endif /* HAVE_LIBPCREPOSIX */
 #include <stdbool.h>
 
 #include "vector.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Tokenizes a string, storing tokens in a vector. Whitespace is ignored.
  * Delimiter characters are not included.
@@ -83,6 +92,29 @@ void frrstr_filter_vec(vector v, regex_t *filter);
  */
 void frrstr_strvec_free(vector v);
 
+/*
+ * Given a string, replaces all occurrences of a substring with a different
+ * string. The result is a new string. The original string is not modified.
+ *
+ * If 'replace' is longer than 'find', this function performs N+1 allocations,
+ * where N is the number of times 'find' occurs in 'str'. If 'replace' is equal
+ * in length or shorter than 'find', only 1 allocation is performed.
+ *
+ * str
+ *    String to perform replacement on.
+ *
+ * find
+ *    Substring to replace.
+ *
+ * replace
+ *    String to replace 'find' with.
+ *
+ * Returns:
+ *    A new string, allocated with MTYPE_TMP, that is the result of performing
+ *    the replacement on 'str'. This must be freed by the caller.
+ */
+char *frrstr_replace(const char *str, const char *find, const char *replace);
+
 /*
  * Prefix match for string.
  *
@@ -93,9 +125,23 @@ void frrstr_strvec_free(vector v);
  *    prefix to look for
  *
  * Returns:
- *   true str starts with prefix, false otherwise
+ *   true if str starts with prefix, false otherwise
+ */
+bool frrstr_startswith(const char *str, const char *prefix);
+
+/*
+ * Suffix match for string.
+ *
+ * str
+ *    string to check for suffix match
+ *
+ * suffix
+ *    suffix to look for
+ *
+ * Returns:
+ *   true if str ends with suffix, false otherwise
  */
-bool begins_with(const char *str, const char *prefix);
+bool frrstr_endswith(const char *str, const char *suffix);
 
 /*
  * Check the string only contains digit characters.
@@ -108,4 +154,8 @@ bool begins_with(const char *str, const char *prefix);
  */
 int all_digit(const char *str);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _FRRSTR_H_ */