line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ifndef _XH_STRING_H_ |
2
|
|
|
|
|
|
|
#define _XH_STRING_H_ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include "xh_config.h" |
5
|
|
|
|
|
|
|
#include "xh_core.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#define xh_str_equal2(p, c0, c1) \ |
8
|
|
|
|
|
|
|
((((uint32_t *) (p))[0] & 0xffff) == ((c1 << 8) | c0)) |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#define xh_str_equal3(p, c0, c1, c2) \ |
11
|
|
|
|
|
|
|
((((uint32_t *) (p))[0] & 0xffffff) == ((c2 << 16) | (c1 << 8) | c0)) |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#define xh_str_equal4(p, c0, c1, c2, c3) \ |
14
|
|
|
|
|
|
|
(*(uint32_t *) (p) == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#define xh_str_equal5(p, c0, c1, c2, c3, c4) \ |
17
|
|
|
|
|
|
|
(xh_str_equal4(p, c0, c1, c2, c3) && (p)[4] == c4) |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#define xh_str_equal6(p, c0, c1, c2, c3, c4, c5) \ |
20
|
|
|
|
|
|
|
(xh_str_equal4(p, c0, c1, c2, c3) && xh_str_equal2(&p[4], c4, c5)) |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#define xh_str_equal7(p, c0, c1, c2, c3, c4, c5, c6) \ |
23
|
|
|
|
|
|
|
(xh_str_equal4(p, c0, c1, c2, c3) && xh_str_equal3(&p[4], c4, c5, c6)) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#define xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) \ |
26
|
|
|
|
|
|
|
(xh_str_equal4(p, c0, c1, c2, c3) && xh_str_equal4(&p[4], c4, c5, c6, c7)) |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#define xh_str_equal9(p, c0, c1, c2, c3, c4, c5, c6, c7, c8) \ |
29
|
|
|
|
|
|
|
(xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) && (p)[8] == c8) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#define xh_str_equal10(p, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9) \ |
32
|
|
|
|
|
|
|
(xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) && xh_str_equal2(&p[8], c8, c9)) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#define xh_str_equal11(p, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) \ |
35
|
|
|
|
|
|
|
(xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) && xh_str_equal3(&p[8], c8, c9, c10)) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#define xh_str_equal12(p, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11)\ |
38
|
|
|
|
|
|
|
(xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) && xh_str_equal4(&p[8], c8, c9, c10, c11)) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#define xh_str_equal13(p, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12)\ |
41
|
|
|
|
|
|
|
(xh_str_equal8(p, c0, c1, c2, c3, c4, c5, c6, c7) && xh_str_equal5(&p[8], c8, c9, c10, c11, c12)) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#define xh_strcmp(s1, s2) strcmp((const char *) (s1), (const char *) (s2)) |
45
|
|
|
|
|
|
|
#define xh_strcasecmp(s1, s2) strcasecmp((const char *) (s1), (const char *) (s2)) |
46
|
|
|
|
|
|
|
#define xh_strncmp(s1, s2, n) strncmp((const char *) (s1), (const char *) (s2), (n)) |
47
|
|
|
|
|
|
|
#define xh_strlen(s) strlen((const char *) (s)) |
48
|
|
|
|
|
|
|
#define xh_strcpy(d, s) strcpy((char *) (d), (const char *) (s)) |
49
|
|
|
|
|
|
|
#define xh_strncpy(d, s, n) strncpy((char *) (d), (const char *) (s), (n)) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
XH_INLINE xh_char_t * |
52
|
1
|
|
|
|
|
|
xh_str_trim(xh_char_t *s, size_t *len) |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
xh_char_t *end, ch; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
|
end = s + *len; |
57
|
|
|
|
|
|
|
|
58
|
4
|
100
|
|
|
|
|
while ((ch = *s++) == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
59
|
1
|
50
|
|
|
|
|
if (ch == '\0') { |
60
|
0
|
|
|
|
|
|
*len = 0; |
61
|
0
|
|
|
|
|
|
return s - 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
|
s--; |
65
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
|
while (--end != s && ((ch = *end) == ' ' || ch == '\t' || ch == '\n' || ch == '\r')); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
|
*len = end - s + 1; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
|
return s; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
XH_INLINE xh_char_t * |
74
|
|
|
|
|
|
|
xh_str_copy(xh_char_t *dest, const xh_char_t *src, size_t n) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
dest[--n] = '\0'; |
77
|
|
|
|
|
|
|
return XH_CHAR_CAST strncpy((char *) dest, (const char *) src, n); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
XH_INLINE xh_char_t * |
81
|
|
|
|
|
|
|
xh_str_range_copy(xh_char_t *dest, const xh_char_t *src, size_t l, size_t n) |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
if (l < n) n = l + 1; |
84
|
|
|
|
|
|
|
dest[--n] = '\0'; |
85
|
|
|
|
|
|
|
return XH_CHAR_CAST strncpy((char *) dest, (const char *) src, n); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
XH_INLINE void |
89
|
|
|
|
|
|
|
xh_memmove(xh_char_t *dest, const xh_char_t *src, size_t n) |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
while (n--) *dest++ = *src++; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
XH_INLINE xh_bool_t |
95
|
|
|
|
|
|
|
xh_str_is_xml(xh_char_t *s) |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
xh_char_t ch; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
while ((ch = *s++) == ' ' || ch =='\t' || ch == '\n' || ch == '\r'); |
100
|
|
|
|
|
|
|
if (ch == '<') return TRUE; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return FALSE; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#endif /* _XH_STRING_H_ */ |