]>
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>
35 * Tokenizes a string, storing tokens in a vector. Whitespace is ignored.
36 * Delimiter characters are not included.
42 * Delimiter string, as used in strsep()
45 * The split string. Each token is allocated with MTYPE_TMP.
47 void frrstr_split(const char *string
, const char *delimiter
, char ***result
,
49 vector
frrstr_split_vec(const char *string
, const char *delimiter
);
52 * Concatenate string array into a single string.
55 * array of string pointers to concatenate
61 * string to insert between each part, or NULL for nothing
64 * the joined string, allocated with MTYPE_TMP
66 char *frrstr_join(const char **parts
, int argc
, const char *join
);
67 char *frrstr_join_vec(vector v
, const char *join
);
70 * Filter string vector.
71 * Removes lines that do not contain a match for the provided regex.
74 * The vector to filter.
77 * Regex to filter with.
79 void frrstr_filter_vec(vector v
, regex_t
*filter
);
82 * Free allocated string vector.
83 * Assumes each item is allocated with MTYPE_TMP.
88 void frrstr_strvec_free(vector v
);
91 * Given a string, replaces all occurrences of a substring with a different
92 * string. The result is a new string. The original string is not modified.
94 * If 'replace' is longer than 'find', this function performs N+1 allocations,
95 * where N is the number of times 'find' occurs in 'str'. If 'replace' is equal
96 * in length or shorter than 'find', only 1 allocation is performed.
99 * String to perform replacement on.
102 * Substring to replace.
105 * String to replace 'find' with.
108 * A new string, allocated with MTYPE_TMP, that is the result of performing
109 * the replacement on 'str'. This must be freed by the caller.
111 char *frrstr_replace(const char *str
, const char *find
, const char *replace
);
113 * Prefix match for string.
116 * string to check for prefix match
122 * true str starts with prefix, false otherwise
124 bool begins_with(const char *str
, const char *prefix
);
127 * Check the string only contains digit characters.
130 * string to check for digits
133 * 1 str only contains digit characters, 0 otherwise
135 int all_digit(const char *str
);
141 #endif /* _FRRSTR_H_ */