summaryrefslogtreecommitdiffstats
path: root/libnetdata/line_splitter/line_splitter.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
commitbe1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /libnetdata/line_splitter/line_splitter.c
parentInitial commit. (diff)
downloadnetdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz
netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/line_splitter/line_splitter.c')
-rw-r--r--libnetdata/line_splitter/line_splitter.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/libnetdata/line_splitter/line_splitter.c b/libnetdata/line_splitter/line_splitter.c
new file mode 100644
index 00000000..a459d334
--- /dev/null
+++ b/libnetdata/line_splitter/line_splitter.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "../libnetdata.h"
+
+
+bool line_splitter_reconstruct_line(BUFFER *wb, void *ptr) {
+ struct line_splitter *spl = ptr;
+ if(!spl) return false;
+
+ size_t added = 0;
+ for(size_t i = 0; i < spl->num_words ;i++) {
+ if(i) buffer_fast_strcat(wb, " ", 1);
+
+ buffer_fast_strcat(wb, "'", 1);
+ const char *s = get_word(spl->words, spl->num_words, i);
+ buffer_strcat(wb, s?s:"");
+ buffer_fast_strcat(wb, "'", 1);
+ added++;
+ }
+
+ return added > 0;
+}
+
+inline int pluginsd_isspace(char c) {
+ switch(c) {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ case '=':
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+inline int config_isspace(char c) {
+ switch (c) {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ case ',':
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+inline int group_by_label_isspace(char c) {
+ if(c == ',' || c == '|')
+ return 1;
+
+ return 0;
+}
+
+bool isspace_map_pluginsd[256] = {};
+bool isspace_map_config[256] = {};
+bool isspace_map_group_by_label[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);
+ }
+}