]>
Commit | Line | Data |
---|---|---|
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> | |
25 | #include <regex.h> | |
2cddf2ff | 26 | #include <stdbool.h> |
fe011935 QY |
27 | |
28 | #include "vector.h" | |
29 | ||
30 | /* | |
31 | * Tokenizes a string, storing tokens in a vector. Whitespace is ignored. | |
32 | * Delimiter characters are not included. | |
33 | * | |
34 | * string | |
35 | * The string to split | |
36 | * | |
37 | * delimiter | |
38 | * Delimiter string, as used in strsep() | |
39 | * | |
40 | * Returns: | |
41 | * The split string. Each token is allocated with MTYPE_TMP. | |
42 | */ | |
43 | void frrstr_split(const char *string, const char *delimiter, char ***result, | |
44 | int *argc); | |
45 | vector frrstr_split_vec(const char *string, const char *delimiter); | |
46 | ||
47 | /* | |
48 | * Concatenate string array into a single string. | |
49 | * | |
50 | * argv | |
51 | * array of string pointers to concatenate | |
52 | * | |
53 | * argc | |
54 | * array length | |
55 | * | |
56 | * join | |
57 | * string to insert between each part, or NULL for nothing | |
58 | * | |
59 | * Returns: | |
60 | * the joined string, allocated with MTYPE_TMP | |
61 | */ | |
62 | char *frrstr_join(const char **parts, int argc, const char *join); | |
63 | char *frrstr_join_vec(vector v, const char *join); | |
64 | ||
65 | /* | |
66 | * Filter string vector. | |
67 | * Removes lines that do not contain a match for the provided regex. | |
68 | * | |
69 | * v | |
70 | * The vector to filter. | |
71 | * | |
72 | * filter | |
73 | * Regex to filter with. | |
74 | */ | |
75 | void frrstr_filter_vec(vector v, regex_t *filter); | |
76 | ||
77 | /* | |
78 | * Free allocated string vector. | |
79 | * Assumes each item is allocated with MTYPE_TMP. | |
80 | * | |
81 | * v | |
82 | * the vector to free | |
83 | */ | |
84 | void frrstr_strvec_free(vector v); | |
85 | ||
2cddf2ff QY |
86 | /* |
87 | * Prefix match for string. | |
88 | * | |
89 | * str | |
90 | * string to check for prefix match | |
91 | * | |
92 | * prefix | |
93 | * prefix to look for | |
94 | * | |
95 | * Returns: | |
96 | * true str starts with prefix, false otherwise | |
97 | */ | |
98 | bool begins_with(const char *str, const char *prefix); | |
fe011935 QY |
99 | |
100 | #endif /* _FRRSTR_H_ */ |