simple_pattern.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_SIMPLE_PATTERN_H
  3. #define NETDATA_SIMPLE_PATTERN_H
  4. #include "../libnetdata.h"
  5. typedef enum {
  6. SIMPLE_PATTERN_EXACT,
  7. SIMPLE_PATTERN_PREFIX,
  8. SIMPLE_PATTERN_SUFFIX,
  9. SIMPLE_PATTERN_SUBSTRING
  10. } SIMPLE_PREFIX_MODE;
  11. typedef void SIMPLE_PATTERN;
  12. // create a simple_pattern from the string given
  13. // default_mode is used in cases where EXACT matches, without an asterisk,
  14. // should be considered PREFIX matches.
  15. SIMPLE_PATTERN *simple_pattern_create(const char *list, const char *separators, SIMPLE_PREFIX_MODE default_mode);
  16. // test if string str is matched from the pattern and fill 'wildcarded' with the parts matched by '*'
  17. int simple_pattern_matches_extract(SIMPLE_PATTERN *list, const char *str, char *wildcarded, size_t wildcarded_size);
  18. // test if string str is matched from the pattern
  19. #define simple_pattern_matches(list, str) simple_pattern_matches_extract(list, str, NULL, 0)
  20. // free a simple_pattern that was created with simple_pattern_create()
  21. // list can be NULL, in which case, this does nothing.
  22. void simple_pattern_free(SIMPLE_PATTERN *list);
  23. void simple_pattern_dump(uint64_t debug_type, SIMPLE_PATTERN *p) ;
  24. int simple_pattern_is_potential_name(SIMPLE_PATTERN *p) ;
  25. char *simple_pattern_iterate(SIMPLE_PATTERN **p);
  26. // Auxiliary function to create a pattern
  27. char *simple_pattern_trim_around_equal(char *src);
  28. #define is_valid_sp(x) ((x) && *(x) && !((x)[0] == '*' && (x)[1] == '\0'))
  29. #endif //NETDATA_SIMPLE_PATTERN_H