32#define av_bprint_room(buf) ((buf)->size - FFMIN((buf)->len, (buf)->size))
33#define av_bprint_is_allocated(buf) ((buf)->str != (buf)->reserved_internal_buffer)
37 char *old_str, *new_str;
38 unsigned min_size, new_size;
40 if (buf->size == buf->size_max)
44 min_size = buf->len + 1 +
FFMIN(UINT_MAX - buf->len - 1, room);
45 new_size = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
46 if (new_size < min_size)
47 new_size =
FFMIN(buf->size_max, min_size);
53 memcpy(new_str, buf->str, buf->len + 1);
62 extra_len =
FFMIN(extra_len, UINT_MAX - 5 - buf->len);
63 buf->len += extra_len;
65 buf->str[
FFMIN(buf->len, buf->size - 1)] = 0;
70 unsigned size_auto = (
char *)buf +
sizeof(*buf) -
71 buf->reserved_internal_buffer;
75 buf->str = buf->reserved_internal_buffer;
98void av_vbprintf(AVBPrint *buf,
const char *fmt, va_list vl_arg)
107 dst = room ? buf->str + buf->len :
NULL;
109 extra_len = vsnprintf(
dst, room, fmt, vl);
113 if (extra_len < room)
131 unsigned room, real_n;
141 real_n =
FFMIN(n, room - 1);
142 memset(buf->str + buf->len,
c, real_n);
149 unsigned room, real_n;
160 memcpy(buf->str + buf->len,
data, real_n);
169 size_t fmt_len = strlen(fmt);
175 if (room && (l = strftime(buf->str + buf->len, room, fmt, tm)))
183 if (room >> 8 > fmt_len)
188 room = !room ? fmt_len + 1 :
189 room <= INT_MAX / 2 ? room * 2 : INT_MAX;
198 if ((l = strftime(buf2,
sizeof(buf2), fmt, tm))) {
206 static const char txt[] =
"[truncated strftime output]";
207 memset(buf->str + buf->len,
'!', room);
208 memcpy(buf->str + buf->len, txt,
FFMIN(
sizeof(txt) - 1, room));
218 unsigned char **mem,
unsigned *actual_size)
223 *mem = *actual_size ? (
unsigned char *) (buf->str + buf->len) :
NULL;
236 unsigned real_size =
FFMIN(buf->len + 1, buf->size);
256 buf->size = real_size;
260#define WHITESPACES " \n\t\r"
291 case '&' :
av_bprintf(dstbuf,
"%s",
"&");
break;
292 case '<' :
av_bprintf(dstbuf,
"%s",
"<");
break;
293 case '>' :
av_bprintf(dstbuf,
"%s",
">");
break;
296 goto XML_DEFAULT_HANDLING;
302 goto XML_DEFAULT_HANDLING;
318 int is_strictly_special = special_chars && strchr(special_chars, *
src);
320 is_strictly_special || strchr(
"'\\", *
src) ||
323 if (is_strictly_special ||
325 (is_special || (is_ws && is_first_last))))
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define av_bprint_is_allocated(buf)
#define av_bprint_room(buf)
static int av_bprint_alloc(AVBPrint *buf, unsigned room)
static void av_bprint_grow(AVBPrint *buf, unsigned extra_len)
#define AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_COUNT_ONLY
#define flags(name, subs,...)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape the content in src and append it to dstbuf.
void av_bprint_get_buffer(AVBPrint *buf, unsigned size, unsigned char **mem, unsigned *actual_size)
Allocate bytes in the buffer for external use.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm)
Append a formatted date and time to a print buffer.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
unsigned unsigned size_max
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
#define AV_ESCAPE_FLAG_STRICT
Escape only specified special characters.
#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double quoted attributes.
#define AV_ESCAPE_FLAG_WHITESPACE
Consider spaces special and escape them even in the middle of the string.
#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single quoted attributes.
@ AV_ESCAPE_MODE_AUTO
Use auto-selected escaping mode.
@ AV_ESCAPE_MODE_XML
Use XML non-markup character data escaping.
@ AV_ESCAPE_MODE_QUOTE
Use single-quote escaping.
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Utility Preprocessor macros.
Memory handling functions.
static const char * ret_str(int v)