bglibs: str.h Source File

bglibs

str.h
1 #ifndef STR__H__
2 #define STR__H__
3
4 #include <stdarg.h>
5 #include "sysdeps.h"
6
25 #define STR_BLOCKSIZE 16
26
30 struct str
31 {
36 char* s;
40 unsigned len;
42 unsigned size;
43 };
45 typedef struct str str;
46
51 struct str_sortentry
52 {
54 const char* str;
56 unsigned long len;
57 };
59 typedef struct str_sortentry str_sortentry;
60
63 extern const char str_lcase_digits[36] __DEPRECATED__;
64 extern const char str_ucase_digits[36] __DEPRECATED__;
69 int str_init(str* s);
70 int str_alloc(str* s, unsigned size, int copy);
72 #define str_ready(S,SZ) str_alloc(S,SZ,0)
73
74 #define str_realloc(S,SZ) str_alloc(S,SZ,1)
75 void str_free(str* s);
76 int str_truncate(str* s, unsigned len);
81 int str_copy(str* s, const str* in);
82 int str_copys(str* s, const char* in);
83 int str_copyb(str* s, const char* in, unsigned len);
84 int str_copyf(str* s, const char* format, ...);
85 int str_copyfv(str* s, const char* format, va_list ap);
86 int str_copyns(str* s, unsigned int count, ...);
87 int str_copy2s(str* s, const char* a, const char* b);
88 int str_copy3s(str* s, const char* a, const char* b, const char* c);
89 int str_copy4s(str* s, const char* a, const char* b, const char* c, const char* d);
90 int str_copy5s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e);
91 int str_copy6s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e, const char* f);
96 int str_cat(str* s, const str* in);
97 int str_cats(str* s, const char* in);
98 int str_catc(str* s, char in);
99 int str_catb(str* s, const char* in, unsigned len);
100 int str_catf(str* s, const char* format, ...);
101 int str_catfv(str* s, const char* format, va_list ap);
102 int str_cati(str* s, long in);
103 int str_catiw(str* s, long in, unsigned width, char pad);
104 int str_catu(str* s, unsigned long in);
105 int str_catuw(str* s, unsigned long in, unsigned width, char pad);
106 int str_catx(str* s, unsigned long in);
107 int str_catxw(str* s, unsigned long in, unsigned width, char pad);
108 int str_catill(str* s, long long in);
109 int str_catiwll(str* s, long long in, unsigned width, char pad);
110 int str_catull(str* s, unsigned long long in);
111 int str_catuwll(str* s, unsigned long long in, unsigned width, char pad);
112 int str_catxll(str* s, unsigned long long in);
113 int str_catxwll(str* s, unsigned long long in, unsigned width, char pad);
114 int str_catsnumw(str* s, long in, unsigned width, char pad,
115 unsigned base, const char* digits);
116 int str_catunumw(str* s, unsigned long in, unsigned width, char pad,
117 unsigned base, const char* digits);
118 int str_catsllnumw(str* s, long long in, unsigned width, char pad,
119 unsigned base, const char* digits);
120 int str_catullnumw(str* s, unsigned long long in, unsigned width, char pad,
121 unsigned base, const char* digits);
122 int str_catns(str* s, unsigned int count, ...);
123 int str_cat2s(str* s, const char* a, const char* b);
124 int str_cat3s(str* s, const char* a, const char* b, const char* c);
125 int str_cat4s(str* s, const char* a, const char* b, const char* c, const char* d);
126 int str_cat5s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e);
127 int str_cat6s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e, const char* f);
128
129 int str_join(str* s, char sep, const str* t);
130 int str_joins(str* s, char sep, const char* in);
131 int str_joinb(str* s, char sep, const char* in, unsigned len);
135 /* @{ */
136 void str_lower(str* s);
137 void str_upper(str* s);
138 long str_subst(str* s, char from, char to);
139 void str_lstrip(str* s);
140 void str_rstrip(str* s);
141 #define str_strip(S) (str_rstrip(S), str_lstrip(S))
142 void str_lcut(str* s, unsigned count);
143 void str_rcut(str* s, unsigned count);
144 int str_sort(str* s, char sep, long count,
145 int (*fn)(const str_sortentry* a, const str_sortentry* b));
146 int str_splice(str* s, unsigned start, unsigned len, const str* r);
147 int str_splices(str* s, unsigned start, unsigned len, const char* r);
148 int str_spliceb(str* s, unsigned start, unsigned len,
149 const char* r, unsigned rlen);
150 long str_xlate(str* s, const char* from, const char* to, unsigned nchars);
155 int str_cmp(const str* a, unsigned aoffset, const str* b, unsigned boffset);
156 int str_cmps(const str* a, unsigned offset, const char* b);
157 int str_cmpb(const str* a, unsigned offset, const char* b, unsigned len);
158
159 int str_diff(const str* a, const str* b);
160 int str_diffs(const str* a, const char* b);
161 int str_diffb(const str* a, const char* b, unsigned len);
162
163 int str_start(const str* a, const str* b);
164 int str_starts(const str* a, const char* b);
165 int str_startb(const str* a, const char* b, unsigned len);
166
167 int str_case_start(const str* a, const str* b);
168 int str_case_starts(const str* a, const char* b);
169 int str_case_startb(const str* a, const char* b, unsigned len);
170
171 int str_end(const str* a, const str* b);
172 int str_ends(const str* a, const char* b);
173 int str_endb(const str* a, const char* b, unsigned len);
174
175 int str_case_end(const str* a, const str* b);
176 int str_case_ends(const str* a, const char* b);
177 int str_case_endb(const str* a, const char* b, unsigned len);
182 void str_buildmap(int map[256], const char* list);
183 unsigned str_count(const str* s, char ch);
184 unsigned str_countof(const str* s, const char* list);
185 #define str_findfirst(S,C) str_findnext(S,C,0)
186 #define str_findfirstof(S,L) str_findnextof(S,L,0)
187 #define str_findfirstnot(S,L) str_findnextnot(S,L,0)
188 #define str_findlast(S,C) str_findprev(S,C,-1)
189 #define str_findlastof(S,L) str_findprevof(S,L,-1)
190 #define str_findlastnot(S,L) str_findprevof(S,L,-1)
191 int str_findnext(const str* s, char ch, unsigned pos);
192 int str_findnextof(const str* s, const char* list, unsigned pos);
193 int str_findnextnot(const str* s, const char* list, unsigned pos);
194 int str_findprev(const str* s, char ch, unsigned pos);
195 int str_findprevof(const str* s, const char* list, unsigned pos);
196 int str_findprevnot(const str* s, const char* list, unsigned pos);
201 int str_match(const str* s, const str* pattern);
202 int str_matchb(const str* s, const char* pptr, unsigned plen);
203 int str_matchs(const str* s, const char* pattern);
204 int str_case_match(const str* s, const str* pattern);
205 int str_case_matchb(const str* s, const char* pptr, unsigned plen);
206 int str_case_matchs(const str* s, const char* pattern);
207 int str_glob(const str* s, const str* pattern);
208 int str_globb(const str* s, const char* pptr, unsigned plen);
209 int str_globs(const str* s, const char* pattern);
210 int str_case_glob(const str* s, const str* pattern);
211 int str_case_globb(const str* s, const char* pptr, unsigned plen);
212 int str_case_globs(const str* s, const char* pattern);
217 #endif
str_xlate
long str_xlate(str *s, const char *from, const char *to, unsigned nchars)
Definition: xlate.c:24
str_findprevof
int str_findprevof(const str *s, const char *list, unsigned pos)
Definition: findprevof.c:22
str_copy2s
int str_copy2s(str *s, const char *a, const char *b)
Definition: copy2s.c:22
str_catc
int str_catc(str *s, char in)
Definition: cat.c:34
str_endb
int str_endb(const str *a, const char *b, unsigned len)
Definition: end.c:35
str_diffb
int str_diffb(const str *a, const char *b, unsigned len)
Definition: diff.c:41
str::s
char * s
Definition: str.h:36
str_cat5s
int str_cat5s(str *s, const char *a, const char *b, const char *c, const char *d, const char *e)
Definition: cat5s.c:22
str_matchs
int str_matchs(const str *s, const char *pattern)
Definition: str/match.c:55
str_copyns
int str_copyns(str *s, unsigned int count,...)
Definition: copyns.c:23
str_copy
int str_copy(str *s, const str *in)
Definition: copy.c:22
str_findprev
int str_findprev(const str *s, char ch, unsigned pos)
Definition: findprev.c:21
str_copy5s
int str_copy5s(str *s, const char *a, const char *b, const char *c, const char *d, const char *e)
Definition: copy5s.c:22
str_catsllnumw
int str_catsllnumw(str *s, long long in, unsigned width, char pad, unsigned base, const char *digits)
Definition: catsllnum.c:23
str_diffs
int str_diffs(const str *a, const char *b)
Definition: diff.c:35
str_cat3s
int str_cat3s(str *s, const char *a, const char *b, const char *c)
Definition: cat3s.c:22
str_copy4s
int str_copy4s(str *s, const char *a, const char *b, const char *c, const char *d)
Definition: copy4s.c:22
str_catf
int str_catf(str *s, const char *format,...)
Definition: catf.c:40
str_findprevnot
int str_findprevnot(const str *s, const char *list, unsigned pos)
Definition: findprevnot.c:22
str_catb
int str_catb(str *s, const char *in, unsigned len)
Definition: cat.c:43
str_copy6s
int str_copy6s(str *s, const char *a, const char *b, const char *c, const char *d, const char *e, const char *f)
Definition: copy6s.c:22
str_cat2s
int str_cat2s(str *s, const char *a, const char *b)
Definition: cat2s.c:22
str_diff
int str_diff(const str *a, const str *b)
Definition: diff.c:29
str_lstrip
void str_lstrip(str *s)
Definition: lstrip.c:23
str_rcut
void str_rcut(str *s, unsigned count)
Definition: cut.c:22
str_catxwll
int str_catxwll(str *s, unsigned long long in, unsigned width, char pad)
Definition: catxwll.c:29
str_sortentry
Definition: str.h:51
str_upper
void str_upper(str *s)
Definition: upper.c:22
str_catuw
int str_catuw(str *s, unsigned long in, unsigned width, char pad)
Definition: catuw.c:22
str_countof
unsigned str_countof(const str *s, const char *list)
Definition: countof.c:21
str_catu
int str_catu(str *s, unsigned long in)
Definition: catuw.c:28
str::len
unsigned len
Definition: str.h:40
str_ends
int str_ends(const str *a, const char *b)
Definition: end.c:23
str_copyf
int str_copyf(str *s, const char *format,...)
Definition: copyf.c:40
str_cmps
int str_cmps(const str *a, unsigned offset, const char *b)
Definition: cmp.c:34
str_copy3s
int str_copy3s(str *s, const char *a, const char *b, const char *c)
Definition: copy3s.c:22
str_catfv
int str_catfv(str *s, const char *format, va_list ap)
Definition: catf.c:22
str_cmpb
int str_cmpb(const str *a, unsigned offset, const char *b, unsigned len)
Definition: cmp.c:40
str_case_start
int str_case_start(const str *a, const str *b)
Definition: case_start.c:45
str_case_match
int str_case_match(const str *s, const str *pattern)
Definition: case_match.c:57
str_catx
int str_catx(str *s, unsigned long in)
Definition: catxw.c:28
str_matchb
int str_matchb(const str *s, const char *pptr, unsigned plen)
Definition: str/match.c:23
str_lcut
void str_lcut(str *s, unsigned count)
Definition: cut.c:30
str_end
int str_end(const str *a, const str *b)
Definition: end.c:29
str_count
unsigned str_count(const str *s, char ch)
Definition: count.c:21
str_catns
int str_catns(str *s, unsigned int count,...)
Definition: catns.c:23
str_join
int str_join(str *s, char sep, const str *t)
Definition: join.c:22
str_ucase_digits
const char str_ucase_digits[36]
Definition: digits.c:7
str_joins
int str_joins(str *s, char sep, const char *in)
Definition: join.c:28
str_copyb
int str_copyb(str *s, const char *in, unsigned len)
Definition: copy.c:34
str_sort
int str_sort(str *s, char sep, long count, int(*fn)(const str_sortentry *a, const str_sortentry *b))
Definition: sort.c:51
str::size
unsigned size
Definition: str.h:42
str_rstrip
void str_rstrip(str *s)
Definition: rstrip.c:22
str_case_endb
int str_case_endb(const str *a, const char *b, unsigned len)
Definition: case_end.c:24
str_truncate
int str_truncate(str *s, unsigned len)
Definition: truncate.c:27
str_case_starts
int str_case_starts(const str *a, const char *b)
Definition: case_start.c:39
str_case_matchs
int str_case_matchs(const str *s, const char *pattern)
Definition: case_match.c:63
str_lower
void str_lower(str *s)
Definition: lower.c:22
str_buildmap
void str_buildmap(int map[256], const char *list)
Definition: buildmap.c:27
str_catullnumw
int str_catullnumw(str *s, unsigned long long in, unsigned width, char pad, unsigned base, const char *digits)
Definition: catullnum.c:23
str_copyfv
int str_copyfv(str *s, const char *format, va_list ap)
Definition: copyf.c:22
str_findnextof
int str_findnextof(const str *s, const char *list, unsigned pos)
Definition: findnextof.c:22
str_case_end
int str_case_end(const str *a, const str *b)
Definition: case_end.c:45
str
Definition: str.h:30
str_catunumw
int str_catunumw(str *s, unsigned long in, unsigned width, char pad, unsigned base, const char *digits)
Definition: catunum.c:22
str_free
void str_free(str *s)
Definition: free.c:24
str_catill
int str_catill(str *s, long long in)
Definition: catiwll.c:22
str_alloc
int str_alloc(str *s, unsigned size, int copy)
Definition: alloc.c:32
str_catiwll
int str_catiwll(str *s, long long in, unsigned width, char pad)
Definition: catiwll.c:29
str_joinb
int str_joinb(str *s, char sep, const char *in, unsigned len)
Definition: join.c:34
str_cmp
int str_cmp(const str *a, unsigned aoffset, const str *b, unsigned boffset)
Definition: cmp.c:28
str_cat6s
int str_cat6s(str *s, const char *a, const char *b, const char *c, const char *d, const char *e, const char *f)
Definition: cat6s.c:22
str_case_ends
int str_case_ends(const str *a, const char *b)
Definition: case_end.c:39
str_startb
int str_startb(const str *a, const char *b, unsigned len)
Definition: start.c:35
str_cats
int str_cats(str *s, const char *in)
Definition: cat.c:28
str_catiw
int str_catiw(str *s, long in, unsigned width, char pad)
Definition: catiw.c:28
str_catull
int str_catull(str *s, unsigned long long in)
Definition: catuwll.c:22
str_catsnumw
int str_catsnumw(str *s, long in, unsigned width, char pad, unsigned base, const char *digits)
Definition: catsnum.c:22
str_cat
int str_cat(str *s, const str *in)
Definition: cat.c:22
str_copys
int str_copys(str *s, const char *in)
Definition: copy.c:28
str_cat4s
int str_cat4s(str *s, const char *a, const char *b, const char *c, const char *d)
Definition: cat4s.c:22
str_cati
int str_cati(str *s, long in)
Definition: catiw.c:22
str_sortentry::len
unsigned long len
Definition: str.h:56
str_findnextnot
int str_findnextnot(const str *s, const char *list, unsigned pos)
Definition: findnextnot.c:22
str_case_matchb
int str_case_matchb(const str *s, const char *pptr, unsigned plen)
Definition: case_match.c:24
str_start
int str_start(const str *a, const str *b)
Definition: start.c:29
str_starts
int str_starts(const str *a, const char *b)
Definition: start.c:23
str_findnext
int str_findnext(const str *s, char ch, unsigned pos)
Definition: findnext.c:22
str_init
int str_init(str *s)
Definition: init.c:22
str_case_startb
int str_case_startb(const str *a, const char *b, unsigned len)
Definition: case_start.c:24
str_sortentry::str
const char * str
Definition: str.h:54
str_catxw
int str_catxw(str *s, unsigned long in, unsigned width, char pad)
Definition: catxw.c:22
str_catxll
int str_catxll(str *s, unsigned long long in)
Definition: catxwll.c:22
str_match
int str_match(const str *s, const str *pattern)
Definition: str/match.c:49
str_subst
long str_subst(str *s, char from, char to)
Definition: subst.c:24
str_catuwll
int str_catuwll(str *s, unsigned long long in, unsigned width, char pad)
Definition: catuwll.c:29