diff options
Diffstat (limited to 'src/libnetdata/line_splitter')
-rw-r--r-- | src/libnetdata/line_splitter/README.md | 9 | ||||
-rw-r--r-- | src/libnetdata/line_splitter/line_splitter.c | 37 | ||||
-rw-r--r-- | src/libnetdata/line_splitter/line_splitter.h | 16 |
3 files changed, 41 insertions, 21 deletions
diff --git a/src/libnetdata/line_splitter/README.md b/src/libnetdata/line_splitter/README.md index b391a492c..1c8263421 100644 --- a/src/libnetdata/line_splitter/README.md +++ b/src/libnetdata/line_splitter/README.md @@ -1,12 +1,3 @@ -<!-- -title: "Log" -custom_edit_url: https://github.com/netdata/netdata/edit/master/src/libnetdata/log/README.md -sidebar_label: "Log" -learn_status: "Published" -learn_topic_type: "Tasks" -learn_rel_path: "Developers/libnetdata" ---> - # Log The netdata log library supports debug, info, error and fatal error logging. diff --git a/src/libnetdata/line_splitter/line_splitter.c b/src/libnetdata/line_splitter/line_splitter.c index 6726d9096..aa56e9b4e 100644 --- a/src/libnetdata/line_splitter/line_splitter.c +++ b/src/libnetdata/line_splitter/line_splitter.c @@ -21,12 +21,29 @@ bool line_splitter_reconstruct_line(BUFFER *wb, void *ptr) { return added > 0; } -inline int pluginsd_isspace(char c) { +inline int isspace_whitespace(char c) { switch(c) { case ' ': case '\t': case '\r': case '\n': + case '\f': + case '\v': + return 1; + + default: + return 0; + } +} + +inline int isspace_pluginsd(char c) { + switch(c) { + case ' ': + case '\t': + case '\r': + case '\n': + case '\f': + case '\v': case '=': return 1; @@ -35,12 +52,14 @@ inline int pluginsd_isspace(char c) { } } -inline int config_isspace(char c) { +inline int isspace_config(char c) { switch (c) { case ' ': case '\t': case '\r': case '\n': + case '\f': + case '\v': case ',': return 1; @@ -49,20 +68,21 @@ inline int config_isspace(char c) { } } -inline int group_by_label_isspace(char c) { +inline int isspace_group_by_label(char c) { if(c == ',' || c == '|') return 1; return 0; } -inline int dyncfg_id_isspace(char c) { +inline int isspace_dyncfg_id(char c) { if(c == ':') return 1; return 0; } +bool isspace_map_whitespace[256] = {}; bool isspace_map_pluginsd[256] = {}; bool isspace_map_config[256] = {}; bool isspace_map_group_by_label[256] = {}; @@ -70,9 +90,10 @@ bool isspace_dyncfg_id_map[256] = {}; __attribute__((constructor)) void initialize_is_space_arrays(void) { for(int c = 0; c < 256 ; c++) { - isspace_map_pluginsd[c] = pluginsd_isspace((char) c); - isspace_map_config[c] = config_isspace((char) c); - isspace_map_group_by_label[c] = group_by_label_isspace((char) c); - isspace_dyncfg_id_map[c] = dyncfg_id_isspace((char)c); + isspace_map_whitespace[c] = isspace_whitespace((char) c); + isspace_map_pluginsd[c] = isspace_pluginsd((char) c); + isspace_map_config[c] = isspace_config((char) c); + isspace_map_group_by_label[c] = isspace_group_by_label((char) c); + isspace_dyncfg_id_map[c] = isspace_dyncfg_id((char) c); } } diff --git a/src/libnetdata/line_splitter/line_splitter.h b/src/libnetdata/line_splitter/line_splitter.h index 968930410..157d91786 100644 --- a/src/libnetdata/line_splitter/line_splitter.h +++ b/src/libnetdata/line_splitter/line_splitter.h @@ -19,11 +19,13 @@ static inline void line_splitter_reset(struct line_splitter *line) { line->num_words = 0; } -int pluginsd_isspace(char c); -int config_isspace(char c); -int group_by_label_isspace(char c); -int dyncfg_id_isspace(char c); +int isspace_pluginsd(char c); +int isspace_config(char c); +int isspace_group_by_label(char c); +int isspace_dyncfg_id(char c); +int isspace_whitespace(char c); +extern bool isspace_map_whitespace[256]; extern bool isspace_map_pluginsd[256]; extern bool isspace_map_config[256]; extern bool isspace_map_group_by_label[256]; @@ -55,6 +57,9 @@ static inline size_t quoted_strings_splitter(char *str, char **words, size_t max while (likely(*s)) { // if it is an escape if (unlikely(*s == '\\' && s[1])) { + // IMPORTANT: support for escaping is incomplete! + // The backslash character needs to be removed + // from the parsed string. s += 2; continue; } @@ -103,6 +108,9 @@ static inline size_t quoted_strings_splitter(char *str, char **words, size_t max return i; } +#define quoted_strings_splitter_whitespace(str, words, max_words) \ + quoted_strings_splitter(str, words, max_words, isspace_map_whitespace) + #define quoted_strings_splitter_query_group_by_label(str, words, max_words) \ quoted_strings_splitter(str, words, max_words, isspace_map_group_by_label) |