summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/simple_pattern
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnetdata/simple_pattern')
-rw-r--r--src/libnetdata/simple_pattern/README.md10
-rw-r--r--src/libnetdata/simple_pattern/simple_pattern.c23
-rw-r--r--src/libnetdata/simple_pattern/simple_pattern.h2
3 files changed, 15 insertions, 20 deletions
diff --git a/src/libnetdata/simple_pattern/README.md b/src/libnetdata/simple_pattern/README.md
index cf8a0f640..93a6f2d8a 100644
--- a/src/libnetdata/simple_pattern/README.md
+++ b/src/libnetdata/simple_pattern/README.md
@@ -1,13 +1,3 @@
-<!--
-title: "Simple patterns"
-description: "Netdata supports simple patterns, which are less cryptic versions of regular expressions. Use familiar notation for powerful results."
-custom_edit_url: https://github.com/netdata/netdata/edit/master/src/libnetdata/simple_pattern/README.md
-sidebar_label: "Simple patterns"
-learn_status: "Published"
-learn_topic_type: "Tasks"
-learn_rel_path: "Developers/libnetdata"
--->
-
# Simple patterns
Unix prefers regular expressions. But they are just too hard, too cryptic
diff --git a/src/libnetdata/simple_pattern/simple_pattern.c b/src/libnetdata/simple_pattern/simple_pattern.c
index 7a7f41b1c..d0feefb4d 100644
--- a/src/libnetdata/simple_pattern/simple_pattern.c
+++ b/src/libnetdata/simple_pattern/simple_pattern.c
@@ -78,18 +78,21 @@ SIMPLE_PATTERN *simple_pattern_create(const char *list, const char *separators,
if(unlikely(!list || !*list)) return root;
- char isseparator[256] = {
- [' '] = 1 // space
- , ['\t'] = 1 // tab
- , ['\r'] = 1 // carriage return
- , ['\n'] = 1 // new line
- , ['\f'] = 1 // form feed
- , ['\v'] = 1 // vertical tab
+ bool isseparator[256] = {
+ [' '] = true // space
+ , ['\t'] = true // tab
+ , ['\r'] = true // carriage return
+ , ['\n'] = true // new line
+ , ['\f'] = true // form feed
+ , ['\v'] = true // vertical tab
};
- if (unlikely(separators && *separators)) {
- memset(&isseparator[0], 0, sizeof(isseparator));
- while(*separators) isseparator[(unsigned char)*separators++] = 1;
+ if (unlikely(separators == SIMPLE_PATTERN_NO_SEPARATORS))
+ memset(isseparator, false, sizeof(isseparator));
+
+ else if (unlikely(separators && *separators)) {
+ memset(isseparator, false, sizeof(isseparator));
+ while(*separators) isseparator[(unsigned char)*separators++] = true;
}
char *buf = mallocz(strlen(list) + 1);
diff --git a/src/libnetdata/simple_pattern/simple_pattern.h b/src/libnetdata/simple_pattern/simple_pattern.h
index 1af0f87b9..2c105c54b 100644
--- a/src/libnetdata/simple_pattern/simple_pattern.h
+++ b/src/libnetdata/simple_pattern/simple_pattern.h
@@ -21,6 +21,8 @@ typedef enum __attribute__ ((__packed__)) {
struct simple_pattern;
typedef struct simple_pattern SIMPLE_PATTERN;
+#define SIMPLE_PATTERN_NO_SEPARATORS (const char *)(0xFFFFFFFF)
+
// create a simple_pattern from the string given
// default_mode is used in cases where EXACT matches, without an asterisk,
// should be considered PREFIX matches.