8#define LIT_ECHAR "\t\b\n\r\f\"\'\\"
14 uint8_t *data = malloc (size + 1);
18 for (
size_t i = 0; i < size;) {
20 if (esc_str[i] ==
'\\') {
23 if (esc_str[i] ==
'u') {
26 }
else if (esc_str[i] ==
'U') {
40 memcpy (tmp_chr, esc_str + i, esc_len);
41 tmp_chr[esc_len] =
'\0';
43 uint32_t tmp_val = strtol ((
char *) tmp_chr, NULL, 16);
49 log_error (
"Error encoding sequence: %s", tmp_chr);
54 memcpy (data + len, tmp_chr, cp_len);
58 LOG_TRACE(
"UC byte value: %2x %2x", data[len], data[len + 1]);
61 "UC byte value: %2x %2x %2x %2x",
62 data[len], data[len + 1], data[len + 2], data[len + 3]
68 data[len++] = esc_str[i++];
73 uint8_t *ret = realloc (data, len);
83 size_t out_size = strlen (in) + 1;
89 i += strcspn (in + i + 1,
LIT_ECHAR) + 1) {
93 char *out = calloc (1, out_size);
98 for (
size_t i = 0, j = 0;;) {
99 out = strncat (out, in + i, boundary);
103 if (i >= strlen (in))
break;
118 char *body =
"Generated by Volksdata v" VOLK_VERSION " on ";
119 time_t now = time (NULL);
121 strftime (date,
sizeof (date),
"%m/%d/%Y", gmtime (&now));
123 char *out = malloc (strlen (pfx) + strlen (body) + strlen (date) + 2);
126 sprintf (out,
"%s%s%s\n", pfx, body, date);
138uint8_t *
uint8_ndup (
const uint8_t *str,
size_t size);
char escape_char(const char c)
#define LIT_ECHAR
List of characters to be escaped in serialized literals.
uint8_t * uint8_ndup(const uint8_t *str, size_t size)
strndup() for unsigned char.
char * fmt_header(char *pfx)
Format an informational header.
char unescape_char(const char c)
Unescape a single character.
VOLK_rc escape_lit(const char *in, char **out_p)
Add escape character (backslash) to illegal literal characters.
uint8_t * uint8_dup(const uint8_t *str)
Parse error information.
uint8_t * unescape_unicode(const uint8_t *esc_str, size_t size)
Replace \uxxxx and \Uxxxxxxxx with Unicode bytes.
int utf8_encode(const uint32_t utf, unsigned char *out)
Encode a code point using UTF-8.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_OK
Generic success return code.