]>
git.proxmox.com Git - mirror_frr.git/blob - lib/frrstr.h
2 * FRR string processing utilities.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
25 #include <sys/types.h>
26 #ifdef HAVE_LIBPCREPOSIX
27 #include <pcreposix.h>
30 #endif /* HAVE_LIBPCREPOSIX */
40 * Tokenizes a string, storing tokens in a vector. Whitespace is ignored.
41 * Delimiter characters are not included.
47 * Delimiter string, as used in strsep()
50 * The split string. Each token is allocated with MTYPE_TMP.
52 void frrstr_split(const char *string
, const char *delimiter
, char ***result
,
54 vector
frrstr_split_vec(const char *string
, const char *delimiter
);
57 * Concatenate string array into a single string.
60 * array of string pointers to concatenate
66 * string to insert between each part, or NULL for nothing
69 * the joined string, allocated with MTYPE_TMP
71 char *frrstr_join(const char **parts
, int argc
, const char *join
);
72 char *frrstr_join_vec(vector v
, const char *join
);
75 * Filter string vector.
76 * Removes lines that do not contain a match for the provided regex.
79 * The vector to filter.
82 * Regex to filter with.
84 void frrstr_filter_vec(vector v
, regex_t
*filter
);
87 * Free allocated string vector.
88 * Assumes each item is allocated with MTYPE_TMP.
93 void frrstr_strvec_free(vector v
);
96 * Given a string, replaces all occurrences of a substring with a different
97 * string. The result is a new string. The original string is not modified.
99 * If 'replace' is longer than 'find', this function performs N+1 allocations,
100 * where N is the number of times 'find' occurs in 'str'. If 'replace' is equal
101 * in length or shorter than 'find', only 1 allocation is performed.
104 * String to perform replacement on.
107 * Substring to replace.
110 * String to replace 'find' with.
113 * A new string, allocated with MTYPE_TMP, that is the result of performing
114 * the replacement on 'str'. This must be freed by the caller.
116 char *frrstr_replace(const char *str
, const char *find
, const char *replace
);
119 * Prefix match for string.
122 * string to check for prefix match
128 * true if str starts with prefix, false otherwise
130 bool frrstr_startswith(const char *str
, const char *prefix
);
133 * Suffix match for string.
136 * string to check for suffix match
142 * true if str ends with suffix, false otherwise
144 bool frrstr_endswith(const char *str
, const char *suffix
);
147 * Check the string only contains digit characters.
150 * string to check for digits
153 * 1 str only contains digit characters, 0 otherwise
155 int all_digit(const char *str
);
158 * Copy the hexadecimal representation of the string to a buffer.
161 * Buffer to copy result into with size of at least (2 * num) + 1.
164 * Size of destination buffer.
167 * String to represent as hexadecimal.
170 * Number of characters to copy.
173 * Pointer to buffer containing resulting hexadecimal representation.
175 char *frrstr_hex(char *buff
, size_t bufsiz
, const uint8_t *str
, size_t num
);
181 #endif /* _FRRSTR_H_ */