1 #include "tcccstring.h"
3 void cstr_realloc(CString
*cstr
, int new_size
)
8 size
= cstr
->size_allocated
;
10 size
= 8; /* no need to allocate a too small first string */
11 while (size
< new_size
)
13 data
= tcc_realloc(cstr
->data_allocated
, size
);
16 cstr
->data_allocated
= data
;
17 cstr
->size_allocated
= size
;
21 void cstr_cat(CString
*cstr
, const char *str
)
34 void cstr_wccat(CString
*cstr
, int ch
)
37 size
= cstr
->size
+ sizeof(nwchar_t
);
38 if (size
> cstr
->size_allocated
)
39 cstr_realloc(cstr
, size
);
40 *(nwchar_t
*)(((unsigned char *)cstr
->data
) + size
- sizeof(nwchar_t
)) = ch
;
44 void cstr_new(CString
*cstr
)
46 memset(cstr
, 0, sizeof(CString
));
49 /* free string and reset it to NULL */
50 void cstr_free(CString
*cstr
)
52 tcc_free(cstr
->data_allocated
);
56 #define cstr_reset(cstr) cstr_free(cstr)
59 void add_char(CString
*cstr
, int c
)
61 if (c
== '\'' || c
== '\"' || c
== '\\') {
62 /* XXX: could be more precise if char or string */
63 cstr_ccat(cstr
, '\\');
65 if (c
>= 32 && c
<= 126) {
68 cstr_ccat(cstr
, '\\');
72 cstr_ccat(cstr
, '0' + ((c
>> 6) & 7));
73 cstr_ccat(cstr
, '0' + ((c
>> 3) & 7));
74 cstr_ccat(cstr
, '0' + (c
& 7));