master
h 56 lines 1.89 KB
Raw
1
2 #ifndef NETDATA_STRING_H
3 #define NETDATA_STRING_H 1
4
5 #include "../libnetdata.h"
6
7 // ----------------------------------------------------------------------------
8 // STRING implementation
9
10 typedef struct netdata_string STRING;
11
12 STRING *string_strdupz(const char *str);
13 STRING *string_strndupz(const char *str, size_t len);
14
15 STRING *string_dup(STRING *string);
16 void string_freez(STRING *string);
17 size_t string_strlen(const STRING *string);
18 const char *string2str(const STRING *string) NEVERNULL;
19 bool string_ends_with_string(const STRING *whole, const STRING *end);
20 bool string_starts_with_string(const STRING *whole, const STRING *end);
21 bool string_ends_with_string_nocase(const STRING *whole, const STRING *end);
22 bool string_starts_with_string_nocase(const STRING *whole, const STRING *prefix);
23 bool string_equals_string_nocase(const STRING *a, const STRING *b);
24 size_t string_destroy(void);
25
26 // keep common prefix/suffix and replace everything else with [x]
27 STRING *string_2way_merge(STRING *a, STRING *b);
28
29 static inline int string_cmp(STRING *s1, STRING *s2) {
30 // STRINGs are deduplicated, so the same strings have the same pointer
31 // when they differ, we do the typical strcmp() comparison
32 return (s1 == s2)?0:strcmp(string2str(s1), string2str(s2));
33 }
34
35 static inline int string_strcmp(STRING *string, const char *s) {
36 return strcmp(string2str(string), s);
37 }
38
39 static inline int string_strncmp(STRING *string, const char *s, size_t n) {
40 return strncmp(string2str(string), s, n);
41 }
42
43 void string_statistics(size_t *inserts, size_t *deletes, size_t *searches, size_t *entries, size_t *references, size_t *memory, size_t *memory_index, size_t *duplications, size_t *releases);
44
45 int string_unittest(size_t entries);
46
47 void string_init(void);
48
49 static inline void cleanup_string_pp(STRING **stringpp) {
50 if(stringpp)
51 string_freez(*stringpp);
52 }
53
54 #define CLEAN_STRING _cleanup_(cleanup_string_pp) STRING
55
56 #endif