]> git.proxmox.com Git - mirror_frr.git/blame - lib/frrstr.h
zebra: fix FPM node reusing VTY_NODE
[mirror_frr.git] / lib / frrstr.h
CommitLineData
fe011935
QY
1/*
2 * FRR string processing utilities.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Quentin Young
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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
19 */
20
21#ifndef _FRRSTR_H_
22#define _FRRSTR_H_
23
24#include <sys/types.h>
beee9b4a
DS
25#include <sys/types.h>
26#ifdef HAVE_LIBPCREPOSIX
27#include <pcreposix.h>
28#else
fe011935 29#include <regex.h>
beee9b4a 30#endif /* HAVE_LIBPCREPOSIX */
2cddf2ff 31#include <stdbool.h>
fe011935
QY
32
33#include "vector.h"
34
5e244469
RW
35#ifdef __cplusplus
36extern "C" {
37#endif
38
fe011935
QY
39/*
40 * Tokenizes a string, storing tokens in a vector. Whitespace is ignored.
41 * Delimiter characters are not included.
42 *
43 * string
44 * The string to split
45 *
46 * delimiter
47 * Delimiter string, as used in strsep()
48 *
49 * Returns:
50 * The split string. Each token is allocated with MTYPE_TMP.
51 */
52void frrstr_split(const char *string, const char *delimiter, char ***result,
53 int *argc);
54vector frrstr_split_vec(const char *string, const char *delimiter);
55
56/*
57 * Concatenate string array into a single string.
58 *
59 * argv
60 * array of string pointers to concatenate
61 *
62 * argc
63 * array length
64 *
65 * join
66 * string to insert between each part, or NULL for nothing
67 *
68 * Returns:
69 * the joined string, allocated with MTYPE_TMP
70 */
71char *frrstr_join(const char **parts, int argc, const char *join);
72char *frrstr_join_vec(vector v, const char *join);
73
74/*
75 * Filter string vector.
76 * Removes lines that do not contain a match for the provided regex.
77 *
78 * v
79 * The vector to filter.
80 *
81 * filter
82 * Regex to filter with.
83 */
84void frrstr_filter_vec(vector v, regex_t *filter);
85
86/*
87 * Free allocated string vector.
88 * Assumes each item is allocated with MTYPE_TMP.
89 *
90 * v
91 * the vector to free
92 */
93void frrstr_strvec_free(vector v);
94
ed1809c9
QY
95/*
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.
98 *
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.
102 *
103 * str
104 * String to perform replacement on.
105 *
106 * find
107 * Substring to replace.
108 *
109 * replace
110 * String to replace 'find' with.
111 *
112 * Returns:
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.
115 */
116char *frrstr_replace(const char *str, const char *find, const char *replace);
90cf59ec 117
2cddf2ff
QY
118/*
119 * Prefix match for string.
120 *
121 * str
122 * string to check for prefix match
123 *
124 * prefix
125 * prefix to look for
126 *
127 * Returns:
90cf59ec
QY
128 * true if str starts with prefix, false otherwise
129 */
130bool frrstr_startswith(const char *str, const char *prefix);
131
132/*
133 * Suffix match for string.
134 *
135 * str
136 * string to check for suffix match
137 *
138 * suffix
139 * suffix to look for
140 *
141 * Returns:
142 * true if str ends with suffix, false otherwise
2cddf2ff 143 */
90cf59ec 144bool frrstr_endswith(const char *str, const char *suffix);
fe011935 145
5d5ba018 146/*
147 * Check the string only contains digit characters.
148 *
149 * str
150 * string to check for digits
151 *
152 * Returns:
153 * 1 str only contains digit characters, 0 otherwise
154 */
155int all_digit(const char *str);
156
5e244469
RW
157#ifdef __cplusplus
158}
159#endif
160
fe011935 161#endif /* _FRRSTR_H_ */