-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl_string.h
86 lines (60 loc) · 2.79 KB
/
dl_string.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef __DL_STRING
#define __DL_STRING
#include "dl_base.h"
#define dl_cpymem(dst, src, n) (((char *) memcpy(dst, src, n)) + (n))
#define dl_tolower(c) (char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
#define dl_toupper(c) (char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
typedef struct _dl_str dl_str;
struct _dl_str{
size_t len;
char *data;
};
#define dl_string(str) { sizeof(str) - 1, (char *) str};
void dl_exit_msg(int err, const char *fmt, ...);
void dl_printf(const char *fmt, ...);
void dl_printf_core(const char *fmt, va_list args);
char * dl_sprintf(char *buf, const char *fmt, ...);
char * dl_snprintf(char *buf, size_t max, const char *fmt, ...);
char * dl_slprintf(char *buf, char *last, const char *fmt, ...);
char * dl_vslprintf(char *buf, char *last, const char *fmt, va_list args);
void dl_strlow(char *dst, char *src, size_t n);
char * dl_strnchr(char *str, int len, char c);
dl_array * dl_split_by_c(dl_pool *p, dl_str *str, char c);
char * dl_strnstr(char *s1, size_t len, char *s2, size_t len_1);
int dl_substr_num(char *s1, size_t len, char *s2, size_t len_1);
dl_array * dl_split_by_s(dl_pool *p, char *s1, size_t len, char *s2, size_t len_1);
dl_list * dl_split_by_s_l(dl_pool *p, char *s1, size_t len, char *s2, size_t len_1);
dl_str *
dl_str_replace(dl_pool *p, char *s1, size_t len, char *s2, size_t len_1, char *s3, size_t len_2);
char *dl_pstrdup(dl_pool *pool, char *data, size_t len);
char *dl_pstrdup_nt(dl_pool *pool, char *data, size_t len);
char *dl_strdup_nt(char *data, size_t len);
int dl_atoi(char *line, size_t n);
char * dl_hton(char *buf, size_t len);
/* base64 */
void dl_encode_base64(dl_str *dst, dl_str *src, int pad);
void dl_encode_base64url(dl_str *dst, dl_str *src);
int dl_decode_base64(dl_str *dst, dl_str *src);
int dl_decode_base64url(dl_str *dst, dl_str *src);
#define base64_len(n) (((n)*4/3 + 3) & ~3)
/* utf8 */
uint32_t dl_utf8_decode(char **p, size_t n);
size_t dl_utf8_length(char *p, size_t n);
/* escape uri */
#define DL_ESCAPE_URI 0
#define DL_ESCAPE_ARGS 1
#define DL_ESCAPE_URI_COMPONENT 2
#define DL_ESCAPE_HTML 3
#define DL_ESCAPE_REFRESH 4
#define DL_UNESCAPE_URI 1
#define DL_UNESCAPE_REDIRECT 2
uintptr_t dl_escape_uri(uchar *dst, uchar *src, size_t size, int type);
void dl_unescape_uri(uchar **dst, uchar **src, size_t size, int type);
uintptr_t dl_escape_html(uchar *dst, uchar *src, size_t size);
uintptr_t dl_escape_json(uchar *dst, uchar *src, size_t size);
uintptr_t dl_hextoi(uchar *line, size_t n);
uchar *dl_hex2bc(uchar *dst, uchar *src, size_t slen, char * prefix);
char * dl_pbc2hex(char *src, size_t len, char * hprefix, dl_pool *pool);
char * dl_bc2hex(char *dst, char *src, size_t len, char * hprefix);
char * dl_memcpy_rev(char *dst, char *src, size_t len);
#endif