14 #ifndef BSTRLIB_INCLUDE
15 #define BSTRLIB_INCLUDE
26 #if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
27 # if defined (__TURBOC__) && !defined (__BORLANDC__)
28 # define BSTRLIB_NOVSNP
34 #define BSTR_BS_BUFF_LENGTH_GET (0)
40 #define cstr2bstr bfromcstr
41 extern bstring bfromcstr (
const char * str);
42 extern bstring bfromcstralloc (
int mlen,
const char * str);
43 extern bstring blk2bstr (
const void * blk,
int len);
44 extern char * bstr2cstr (const_bstring s,
char z);
45 extern int bcstrfree (
char * s);
46 extern bstring bstrcpy (const_bstring b1);
47 extern int bassign (bstring a, const_bstring b);
48 extern int bassignmidstr (bstring a, const_bstring b,
int left,
int len);
49 extern int bassigncstr (bstring a,
const char * str);
50 extern int bassignblk (bstring a,
const void * s,
int len);
53 extern int bdestroy (bstring b);
56 extern int balloc (bstring s,
int len);
57 extern int ballocmin (bstring b,
int len);
60 extern bstring bmidstr (const_bstring b,
int left,
int len);
63 extern int bconcat (bstring b0, const_bstring b1);
64 extern int bconchar (bstring b0,
char c);
65 extern int bcatcstr (bstring b,
const char * s);
66 extern int bcatblk (bstring b,
const void * s,
int len);
67 extern int binsert (bstring s1,
int pos, const_bstring s2,
unsigned char fill);
68 extern int binsertch (bstring s1,
int pos,
int len,
unsigned char fill);
69 extern int breplace (bstring b1,
int pos,
int len, const_bstring b2,
unsigned char fill);
70 extern int bdelete (bstring s1,
int pos,
int len);
71 extern int bsetstr (bstring b0,
int pos, const_bstring b1,
unsigned char fill);
72 extern int btrunc (bstring b,
int n);
75 extern int bstricmp (const_bstring b0, const_bstring b1);
76 extern int bstrnicmp (const_bstring b0, const_bstring b1,
int n);
77 extern int biseqcaseless (const_bstring b0, const_bstring b1);
78 extern int bisstemeqcaselessblk (const_bstring b0,
const void * blk,
int len);
79 extern int biseq (const_bstring b0, const_bstring b1);
80 extern int bisstemeqblk (const_bstring b0,
const void * blk,
int len);
81 extern int biseqcstr (const_bstring b,
const char * s);
82 extern int biseqcstrcaseless (const_bstring b,
const char * s);
83 extern int bstrcmp (const_bstring b0, const_bstring b1);
84 extern int bstrncmp (const_bstring b0, const_bstring b1,
int n);
85 extern int binstr (const_bstring s1,
int pos, const_bstring s2);
86 extern int binstrr (const_bstring s1,
int pos, const_bstring s2);
87 extern int binstrcaseless (const_bstring s1,
int pos, const_bstring s2);
88 extern int binstrrcaseless (const_bstring s1,
int pos, const_bstring s2);
89 extern int bstrchrp (const_bstring b,
int c,
int pos);
90 extern int bstrrchrp (const_bstring b,
int c,
int pos);
91 #define bstrchr(b,c) bstrchrp ((b), (c), 0)
92 #define bstrrchr(b,c) bstrrchrp ((b), (c), blength(b)-1)
93 extern int binchr (const_bstring b0,
int pos, const_bstring b1);
94 extern int binchrr (const_bstring b0,
int pos, const_bstring b1);
95 extern int bninchr (const_bstring b0,
int pos, const_bstring b1);
96 extern int bninchrr (const_bstring b0,
int pos, const_bstring b1);
97 extern int bfindreplace (bstring b, const_bstring find, const_bstring repl,
int pos);
98 extern int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl,
int pos);
105 extern struct bstrList * bstrListCreate (
void);
106 extern int bstrListDestroy (
struct bstrList * sl);
107 extern int bstrListAlloc (
struct bstrList * sl,
int msz);
108 extern int bstrListAllocMin (
struct bstrList * sl,
int msz);
111 extern struct bstrList * bsplit (const_bstring str,
unsigned char splitChar);
112 extern struct bstrList * bsplits (const_bstring str, const_bstring splitStr);
113 extern struct bstrList * bsplitstr (const_bstring str, const_bstring splitStr);
114 extern bstring bjoin (
const struct bstrList * bl, const_bstring sep);
115 extern int bsplitcb (const_bstring str,
unsigned char splitChar,
int pos,
116 int (* cb) (
void * parm,
int ofs,
int len),
void * parm);
117 extern int bsplitscb (const_bstring str, const_bstring splitStr,
int pos,
118 int (* cb) (
void * parm,
int ofs,
int len),
void * parm);
119 extern int bsplitstrcb (const_bstring str, const_bstring splitStr,
int pos,
120 int (* cb) (
void * parm,
int ofs,
int len),
void * parm);
123 extern int bpattern (bstring b,
int len);
124 extern int btoupper (bstring b);
125 extern int btolower (bstring b);
126 extern int bltrimws (bstring b);
127 extern int brtrimws (bstring b);
128 extern int btrimws (bstring b);
130 #if !defined (BSTRLIB_NOVSNP)
131 extern bstring bformat (
const char * fmt, ...);
132 extern int bformata (bstring b,
const char * fmt, ...);
133 extern int bassignformat (bstring b,
const char * fmt, ...);
134 extern int bvcformata (bstring b,
int count,
const char * fmt, va_list arglist);
136 #define bvformata(ret, b, fmt, lastarg) { \
137 bstring bstrtmp_b = (b); \
138 const char * bstrtmp_fmt = (fmt); \
139 int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
141 va_list bstrtmp_arglist; \
142 va_start (bstrtmp_arglist, lastarg); \
143 bstrtmp_r = bvcformata (bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, bstrtmp_arglist); \
144 va_end (bstrtmp_arglist); \
145 if (bstrtmp_r >= 0) { \
146 bstrtmp_r = BSTR_OK; \
148 } else if (-bstrtmp_r <= bstrtmp_sz) { \
149 bstrtmp_r = BSTR_ERR; \
152 bstrtmp_sz = -bstrtmp_r; \
159 typedef int (*bNgetc) (
void *parm);
160 typedef size_t (* bNread) (
void *buff,
size_t elsize,
size_t nelem,
void *parm);
163 extern bstring bgets (bNgetc getcPtr,
void * parm,
char terminator);
164 extern bstring bread (bNread readPtr,
void * parm);
165 extern int bgetsa (bstring b, bNgetc getcPtr,
void * parm,
char terminator);
166 extern int bassigngets (bstring b, bNgetc getcPtr,
void * parm,
char terminator);
167 extern int breada (bstring b, bNread readPtr,
void * parm);
170 extern struct bStream * bsopen (bNread readPtr,
void * parm);
171 extern void * bsclose (
struct bStream * s);
172 extern int bsbufflength (
struct bStream * s,
int sz);
173 extern int bsreadln (bstring b,
struct bStream * s,
char terminator);
174 extern int bsreadlns (bstring r,
struct bStream * s, const_bstring term);
175 extern int bsread (bstring b,
struct bStream * s,
int n);
176 extern int bsreadlna (bstring b,
struct bStream * s,
char terminator);
177 extern int bsreadlnsa (bstring r,
struct bStream * s, const_bstring term);
178 extern int bsreada (bstring b,
struct bStream * s,
int n);
179 extern int bsunread (
struct bStream * s, const_bstring b);
180 extern int bspeek (bstring r,
const struct bStream * s);
181 extern int bssplitscb (
struct bStream * s, const_bstring splitStr,
182 int (* cb) (
void * parm,
int ofs, const_bstring entry),
void * parm);
183 extern int bssplitstrcb (
struct bStream * s, const_bstring splitStr,
184 int (* cb) (
void * parm,
int ofs, const_bstring entry),
void * parm);
185 extern int bseof (
const struct bStream * s);
190 unsigned char * data;
194 #define blengthe(b, e) (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
195 #define blength(b) (blengthe ((b), 0))
196 #define bdataofse(b, o, e) (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
197 #define bdataofs(b, o) (bdataofse ((b), (o), (void *)0))
198 #define bdatae(b, e) (bdataofse (b, 0, e))
199 #define bdata(b) (bdataofs (b, 0))
200 #define bchare(b, p, e) ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
201 #define bchar(b, p) bchare ((b), (p), '\0')
204 #define bsStaticMlen(q,m) {(m), (int) sizeof(q)-1, (unsigned char *) ("" q "")}
205 #if defined(_MSC_VER)
206 # define bsStatic(q) bsStaticMlen(q,-32)
209 # define bsStatic(q) bsStaticMlen(q,-__LINE__)
213 #define bsStaticBlkParms(q) ((void *)("" q "")), ((int) sizeof(q)-1)
216 #define cstr2tbstr btfromcstr
217 #define btfromcstr(t,s) { \
218 (t).data = (unsigned char *) (s); \
219 (t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
222 #define blk2tbstr(t,s,l) { \
223 (t).data = (unsigned char *) (s); \
227 #define btfromblk(t,s,l) blk2tbstr(t,s,l)
228 #define bmid2tbstr(t,b,p,l) { \
229 const_bstring bstrtmp_s = (b); \
230 if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
231 int bstrtmp_left = (p); \
232 int bstrtmp_len = (l); \
233 if (bstrtmp_left < 0) { \
234 bstrtmp_len += bstrtmp_left; \
237 if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
238 bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
239 if (bstrtmp_len <= 0) { \
240 (t).data = (unsigned char *)""; \
243 (t).data = bstrtmp_s->data + bstrtmp_left; \
244 (t).slen = bstrtmp_len; \
247 (t).data = (unsigned char *)""; \
250 (t).mlen = -__LINE__; \
252 #define btfromblkltrimws(t,s,l) { \
253 int bstrtmp_idx = 0, bstrtmp_len = (l); \
254 unsigned char * bstrtmp_s = (s); \
255 if (bstrtmp_s && bstrtmp_len >= 0) { \
256 for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
257 if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
260 (t).data = bstrtmp_s + bstrtmp_idx; \
261 (t).slen = bstrtmp_len - bstrtmp_idx; \
262 (t).mlen = -__LINE__; \
264 #define btfromblkrtrimws(t,s,l) { \
265 int bstrtmp_len = (l) - 1; \
266 unsigned char * bstrtmp_s = (s); \
267 if (bstrtmp_s && bstrtmp_len >= 0) { \
268 for (; bstrtmp_len >= 0; bstrtmp_len--) { \
269 if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
272 (t).data = bstrtmp_s; \
273 (t).slen = bstrtmp_len + 1; \
274 (t).mlen = -__LINE__; \
276 #define btfromblktrimws(t,s,l) { \
277 int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
278 unsigned char * bstrtmp_s = (s); \
279 if (bstrtmp_s && bstrtmp_len >= 0) { \
280 for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
281 if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
283 for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
284 if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
287 (t).data = bstrtmp_s + bstrtmp_idx; \
288 (t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
289 (t).mlen = -__LINE__; \
293 #define bwriteprotect(t) { if ((t).mlen >= 0) (t).mlen = -1; }
294 #define bwriteallow(t) { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
295 #define biswriteprotected(t) ((t).mlen <= 0)
Definition: bstrlib.h:101
Definition: bstrlib.c:1896
Definition: bstrlib.h:187