47 __attribute__ ((visibility ("default")))
48 #define BSTR_PRIVATE \
49 __attribute__ ((visibility ("hidden")))
55 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
56 #define BSTR_PRINTF(format, argument) \
57 __attribute__ ((__format__ (__printf__, format, argument)))
59 __attribute__ ((__unused__))
61 #define BSTR_PRINTF(format, argument)
76 #define BSTR_BS_BUFF_LENGTH_GET (0)
87 #define cstr2bstr bfromcstr
180 bassign(bstring a,
const bstring b);
191 bassignmidstr(bstring a,
const bstring b,
int left,
int len);
211 bassignblk(bstring a,
const void *s,
int len);
263 balloc(bstring s,
int len);
302 bmidstr(
const bstring b,
int left,
int len);
313 bconcat(bstring b0,
const bstring b1);
340 bcatblk(bstring b,
const void *s,
int len);
351 binsert(bstring s1,
int pos,
const bstring s2,
unsigned char fill);
363 binsertch(bstring s1,
int pos,
int len,
unsigned char fill);
373 breplace(bstring b1,
int pos,
int len,
const bstring b2,
unsigned char fill);
385 bdelete(bstring s1,
int pos,
int len);
396 bsetstr(bstring b0,
int pos,
const bstring b1,
unsigned char fill);
419 bstricmp(
const bstring b0,
const bstring b1);
432 bstrnicmp(
const bstring b0,
const bstring b1,
int n);
468 biseq(
const bstring b0,
const bstring b1);
479 bisstemeqblk(
const bstring b0,
const void *blk,
int len);
493 biseqcstr(
const bstring b,
const char *s);
533 bstrcmp(
const bstring b0,
const bstring b1);
550 bstrncmp(
const bstring b0,
const bstring b1,
int n);
561 binstr(
const bstring s1,
int pos,
const bstring s2);
574 binstrr(
const bstring s1,
int pos,
const bstring s2);
607 bstrchrp(
const bstring b,
int c,
int pos);
616 bstrrchrp(
const bstring b,
int c,
int pos);
624 #define bstrchr(b, c) \
625 bstrchrp((b), (c), 0)
633 #define bstrrchr(b, c) \
634 bstrrchrp((b), (c), blength(b) - 1)
644 binchr(
const bstring b0,
int pos,
const bstring b1);
654 binchrr(
const bstring b0,
int pos,
const bstring b1);
664 bninchr(
const bstring b0,
int pos,
const bstring b1);
674 bninchrr(
const bstring b0,
int pos,
const bstring b1);
698 bfindreplace(bstring b,
const bstring find,
const bstring repl,
int pos);
790 bsplit(
const bstring str,
unsigned char splitChar);
800 bsplits(
const bstring str,
const bstring splitStr);
810 bsplitstr(
const bstring str,
const bstring splitStr);
851 unsigned char splitChar,
853 int(*cb)(
void *parm,
int ofs,
int len),
878 const bstring splitStr,
880 int(*cb)(
void *parm,
int ofs,
int len),
905 const bstring splitStr,
907 int(*cb)(
void *parm,
int ofs,
int len),
void *parm);
1009 bformata(bstring b,
const char *fmt, ...);
1059 bvcformata(bstring b,
int count,
const char *fmt, va_list arglist);
1086 #define bvformata(ret, b, fmt, lastarg) \
1088 bstring bstrtmp_b =(b); \
1089 const char *bstrtmp_fmt = (fmt); \
1090 int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
1092 va_list bstrtmp_arglist; \
1093 va_start(bstrtmp_arglist, lastarg); \
1094 bstrtmp_r = bvcformata(bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, \
1096 va_end(bstrtmp_arglist); \
1097 if(bstrtmp_r >= 0) { \
1099 bstrtmp_r = BSTR_OK; \
1101 } else if(-bstrtmp_r <= bstrtmp_sz) { \
1103 bstrtmp_r = BSTR_ERR; \
1107 bstrtmp_sz = -bstrtmp_r; \
1112 typedef int (*bNgetc)(
void *parm);
1114 typedef size_t (*bNread)(
void *buff,
size_t elsize,
size_t nelem,
void *parm);
1153 bgets(bNgetc getcPtr,
void *parm,
char terminator);
1169 bread(bNread readPtr,
void *parm);
1180 bgetsa(bstring b, bNgetc getcPtr,
void *parm,
char terminator);
1191 bassigngets(bstring b, bNgetc getcPtr,
void *parm,
char terminator);
1200 breada(bstring b, bNread readPtr,
void *parm);
1209 BSTR_PUBLIC
struct bStream *
1210 bsopen(bNread readPtr,
void *parm);
1243 bsreadln(bstring b,
struct bStream *s,
char terminator);
1254 bsreadlns(bstring r,
struct bStream *s,
const bstring term);
1265 bsread(bstring b,
struct bStream *s,
int n);
1279 bsreadlna(bstring b,
struct bStream *s,
char terminator);
1292 bsreadlnsa(bstring r,
struct bStream *s,
const bstring term);
1303 bsreada(bstring b,
struct bStream *s,
int n);
1312 bsunread(
struct bStream *s,
const bstring b);
1320 bspeek(bstring r,
const struct bStream *s);
1348 const bstring splitStr,
1349 int(*cb)(
void *parm,
int ofs,
const bstring entry),
1378 const bstring splitStr,
1379 int(*cb)(
void *parm,
int ofs,
const bstring entry),
1400 bseof(
const struct bStream *s);
1409 #define blengthe(b, e) \
1410 (((b) == (void *)0 || (b)->slen < 0) \
1419 #define blength(b) \
1427 #define bdataofse(b, o, e) \
1428 (((b) == (void *)0 || (b)->data == (void *)0) \
1430 : ((char *)(b)->data) + (o))
1437 #define bdataofs(b, o) \
1438 (bdataofse((b),(o),(void *)0))
1445 #define bdatae(b, e) \
1446 (bdataofse(b, 0, e))
1462 #define bchare(b, p, e) \
1463 ((((unsigned)(p)) < (unsigned)blength(b)) \
1464 ? ((b)->data[(p)]) \
1473 #define bchar(b, p) \
1474 bchare((b), (p), '\0')
1480 #define bsStaticMlen(q, m) { (m), (int)sizeof(q) - 1, (unsigned char *)("" q "") }
1482 #if defined (_MSC_VER)
1497 #define bsStatic(q) bsStaticMlen(q, -32)
1503 #define bsStatic(q) bsStaticMlen(q, -__LINE__)
1526 #define bsStaticBlkParms(q) \
1527 ((void *)("" q "")), ((int)sizeof(q) -1)
1533 #define cstr2tbstr btfromcstr
1548 #define btfromcstr(t, s) \
1550 (t).data = (unsigned char *)(s); \
1551 (t).slen = ((t).data) \
1552 ? ((int)(strlen)((char *)(t).data)) \
1559 #define blk2tbstr(t, s, l) \
1561 (t).data = (unsigned char *)(s); \
1580 #define btfromblk(t, s, l) blk2tbstr(t, s, l)
1597 #define bmid2tbstr(t, b, p, l) \
1599 const bstring bstrtmp_s =(b); \
1600 if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
1601 int bstrtmp_left = (p); \
1602 int bstrtmp_len = (l); \
1603 if (bstrtmp_left < 0) { \
1604 bstrtmp_len += bstrtmp_left; \
1607 if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) { \
1608 bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
1610 if(bstrtmp_len <= 0) { \
1611 (t).data =(unsigned char *)""; \
1614 (t).data = bstrtmp_s->data + bstrtmp_left; \
1615 (t).slen = bstrtmp_len; \
1618 (t).data = (unsigned char *)""; \
1621 (t).mlen = -__LINE__; \
1638 #define btfromblkltrimws(t, s, l) \
1640 int bstrtmp_idx = 0, bstrtmp_len =(l); \
1641 unsigned char *bstrtmp_s = (s); \
1642 if (bstrtmp_s && bstrtmp_len >= 0) { \
1643 for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
1644 if (!isspace(bstrtmp_s[bstrtmp_idx])) { \
1649 (t).data = bstrtmp_s + bstrtmp_idx; \
1650 (t).slen = bstrtmp_len - bstrtmp_idx; \
1651 (t).mlen = -__LINE__; \
1668 #define btfromblkrtrimws(t, s, l) \
1670 int bstrtmp_len = (l) - 1; \
1671 unsigned char *bstrtmp_s = (s); \
1672 if (bstrtmp_s && bstrtmp_len >= 0) { \
1673 for (; bstrtmp_len >= 0; bstrtmp_len--) { \
1674 if (!isspace(bstrtmp_s[bstrtmp_len])) { \
1679 (t).data = bstrtmp_s; \
1680 (t).slen = bstrtmp_len + 1; \
1681 (t).mlen = -__LINE__; \
1698 #define btfromblktrimws(t, s, l) \
1700 int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
1701 unsigned char *bstrtmp_s = (s); \
1702 if (bstrtmp_s && bstrtmp_len >= 0) { \
1703 for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
1704 if(!isspace(bstrtmp_s[bstrtmp_idx])) { \
1708 for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
1709 if (!isspace(bstrtmp_s[bstrtmp_len])) { \
1714 (t).data = bstrtmp_s + bstrtmp_idx; \
1715 (t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
1716 (t).mlen = -__LINE__; \
1729 #define bwriteprotect(t) \
1731 if ((t).mlen >= 0) { \
1748 #define bwriteallow(t) \
1750 if ((t).mlen == -1) { \
1751 (t).mlen = (t).slen + ((t).slen == 0); \
1758 #define biswriteprotected(t) \