]> git.proxmox.com Git - mirror_frr.git/blame - lib/frrstr.h
Merge pull request #4234 from donaldsharp/flood_the_vtep
[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>
25#include <regex.h>
2cddf2ff 26#include <stdbool.h>
fe011935
QY
27
28#include "vector.h"
29
5e244469
RW
30#ifdef __cplusplus
31extern "C" {
32#endif
33
fe011935
QY
34/*
35 * Tokenizes a string, storing tokens in a vector. Whitespace is ignored.
36 * Delimiter characters are not included.
37 *
38 * string
39 * The string to split
40 *
41 * delimiter
42 * Delimiter string, as used in strsep()
43 *
44 * Returns:
45 * The split string. Each token is allocated with MTYPE_TMP.
46 */
47void frrstr_split(const char *string, const char *delimiter, char ***result,
48 int *argc);
49vector frrstr_split_vec(const char *string, const char *delimiter);
50
51/*
52 * Concatenate string array into a single string.
53 *
54 * argv
55 * array of string pointers to concatenate
56 *
57 * argc
58 * array length
59 *
60 * join
61 * string to insert between each part, or NULL for nothing
62 *
63 * Returns:
64 * the joined string, allocated with MTYPE_TMP
65 */
66char *frrstr_join(const char **parts, int argc, const char *join);
67char *frrstr_join_vec(vector v, const char *join);
68
69/*
70 * Filter string vector.
71 * Removes lines that do not contain a match for the provided regex.
72 *
73 * v
74 * The vector to filter.
75 *
76 * filter
77 * Regex to filter with.
78 */
79void frrstr_filter_vec(vector v, regex_t *filter);
80
81/*
82 * Free allocated string vector.
83 * Assumes each item is allocated with MTYPE_TMP.
84 *
85 * v
86 * the vector to free
87 */
88void frrstr_strvec_free(vector v);
89
2cddf2ff
QY
90/*
91 * Prefix match for string.
92 *
93 * str
94 * string to check for prefix match
95 *
96 * prefix
97 * prefix to look for
98 *
99 * Returns:
100 * true str starts with prefix, false otherwise
101 */
102bool begins_with(const char *str, const char *prefix);
fe011935 103
5d5ba018 104/*
105 * Check the string only contains digit characters.
106 *
107 * str
108 * string to check for digits
109 *
110 * Returns:
111 * 1 str only contains digit characters, 0 otherwise
112 */
113int all_digit(const char *str);
114
5e244469
RW
115#ifdef __cplusplus
116}
117#endif
118
fe011935 119#endif /* _FRRSTR_H_ */