6 static bool text_vprintf(Text
*txt
, size_t pos
, const char *format
, va_list ap
) {
9 int len
= vsnprintf(NULL
, 0, format
, ap
);
14 char *buf
= malloc(len
+1);
15 bool ret
= buf
&& (vsnprintf(buf
, len
+1, format
, ap_save
) == len
) && text_insert(txt
, pos
, buf
, len
);
21 bool text_appendf(Text
*txt
, const char *format
, ...) {
24 bool ret
= text_vprintf(txt
, text_size(txt
), format
, ap
);
29 bool text_printf(Text
*txt
, size_t pos
, const char *format
, ...) {
32 bool ret
= text_vprintf(txt
, pos
, format
, ap
);
37 bool text_byte_get(const Text
*txt
, size_t pos
, char *byte
) {
38 return text_bytes_get(txt
, pos
, 1, byte
);
41 size_t text_bytes_get(const Text
*txt
, size_t pos
, size_t len
, char *buf
) {
46 for (Iterator it
= text_iterator_get(txt
, pos
);
47 text_iterator_valid(&it
);
48 text_iterator_next(&it
)) {
51 size_t piece_len
= it
.end
- it
.text
;
55 memcpy(cur
, it
.text
, piece_len
);
63 char *text_bytes_alloc0(const Text
*txt
, size_t pos
, size_t len
) {
66 char *buf
= malloc(len
+1);
69 len
= text_bytes_get(txt
, pos
, len
, buf
);