| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "../libnetdata.h" |
| 4 | |
| 5 | |
| 6 | bool line_splitter_reconstruct_line(BUFFER *wb, void *ptr) { |
| 7 | struct line_splitter *spl = ptr; |
| 8 | if(!spl) return false; |
| 9 | |
| 10 | size_t added = 0; |
| 11 | for(size_t i = 0; i < spl->num_words ;i++) { |
| 12 | if(i) buffer_fast_strcat(wb, " ", 1); |
| 13 | |
| 14 | buffer_fast_strcat(wb, "'", 1); |
| 15 | const char *s = get_word(spl->words, spl->num_words, i); |
| 16 | buffer_strcat(wb, s?s:""); |
| 17 | buffer_fast_strcat(wb, "'", 1); |
| 18 | added++; |
| 19 | } |
| 20 | |
| 21 | return added > 0; |
| 22 | } |
| 23 | |
| 24 | inline int isspace_whitespace(char c) { |
| 25 | switch(c) { |
| 26 | case ' ': |
| 27 | case '\t': |
| 28 | case '\r': |
| 29 | case '\n': |
| 30 | case '\f': |
| 31 | case '\v': |
| 32 | return 1; |
| 33 | |
| 34 | default: |
| 35 | return 0; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | inline int isspace_pluginsd(char c) { |
| 40 | switch(c) { |
| 41 | case ' ': |
| 42 | case '\t': |
| 43 | case '\r': |
| 44 | case '\n': |
| 45 | case '\f': |
| 46 | case '\v': |
| 47 | case '=': |
| 48 | return 1; |
| 49 | |
| 50 | default: |
| 51 | return 0; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | inline int isspace_config(char c) { |
| 56 | switch (c) { |
| 57 | case ' ': |
| 58 | case '\t': |
| 59 | case '\r': |
| 60 | case '\n': |
| 61 | case '\f': |
| 62 | case '\v': |
| 63 | case ',': |
| 64 | return 1; |
| 65 | |
| 66 | default: |
| 67 | return 0; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | inline int isspace_group_by_label(char c) { |
| 72 | if(c == ',' || c == '|') |
| 73 | return 1; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | inline int isspace_dyncfg_id(char c) { |
| 79 | if(c == ':') |
| 80 | return 1; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | bool isspace_map_whitespace[256] = {}; |
| 86 | bool isspace_map_pluginsd[256] = {}; |
| 87 | bool isspace_map_config[256] = {}; |
| 88 | bool isspace_map_group_by_label[256] = {}; |
| 89 | bool isspace_dyncfg_id_map[256] = {}; |
| 90 | |
| 91 | __attribute__((constructor)) void initialize_is_space_arrays(void) { |
| 92 | for(int c = 0; c < 256 ; c++) { |
| 93 | isspace_map_whitespace[c] = isspace_whitespace((char) c); |
| 94 | isspace_map_pluginsd[c] = isspace_pluginsd((char) c); |
| 95 | isspace_map_config[c] = isspace_config((char) c); |
| 96 | isspace_map_group_by_label[c] = isspace_group_by_label((char) c); |
| 97 | isspace_dyncfg_id_map[c] = isspace_dyncfg_id((char) c); |
| 98 | } |
| 99 | } |