simple_pattern.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. extern 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. extern 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. extern void simple_pattern_free(SIMPLE_PATTERN *list);
  23. extern void simple_pattern_dump(uint64_t debug_type, SIMPLE_PATTERN *p) ;
  24. extern int simple_pattern_is_potential_name(SIMPLE_PATTERN *p) ;
  25. extern char *simple_pattern_iterate(SIMPLE_PATTERN **p);
  26. //Auxiliary function to create a pattern
  27. char *simple_pattern_trim_around_equal(char *src);
  28. #endif //NETDATA_SIMPLE_PATTERN_H