mess822x 1.23
mess822x
Loading...
Searching...
No Matches
mess822_token.c
Go to the documentation of this file.
1#include "mess822.h"
2
3/* artificial delimiter is '|' not '=' because '=' is used for keyvalue */
4
5int mess822_token(stralloc *out,char *in)
6{
7 char ch;
8 int level;
9
10 if (!stralloc_copys(out,"")) return 0;
11
12 for (;;)
13 switch (ch = *in++) {
14 case 0:
15 return 1;
16
17 case '"':
18 if (!stralloc_append(out,"|")) return 0;
19 while (*in) {
20 ch = *in++;
21 if (ch == '"') break;
22 if (ch == '\\') if (*in) ch = *in++;
23 if (!stralloc_append(out,&ch)) return 0;
24 }
25 if (!stralloc_0(out)) return 0;
26 break;
27
28 case '[':
29 if (!stralloc_append(out,"|")) return 0;
30 if (!stralloc_append(out,"[")) return 0;
31 while (*in) {
32 ch = *in++;
33 if (ch == ']') break;
34 if (ch == '\\') if (*in) ch = *in++;
35 if (!stralloc_append(out,&ch)) return 0;
36 }
37 if (!stralloc_append(out,"]")) return 0;
38 if (!stralloc_0(out)) return 0;
39 break;
40
41 case '(':
42 if (!stralloc_append(out,"(")) return 0;
43 level = 1;
44 while (*in) {
45 ch = *in++;
46 if (ch == ')') {
47 --level;
48 if (!level) break;
49 if (!stralloc_append(out,")")) return 0;
50 continue;
51 }
52 if (ch == '(') {
53 if (level) if (!stralloc_append(out,"(")) return 0;
54 ++level;
55 continue;
56 }
57 if (ch == '\\') if (*in) ch = *in++;
58 if (!stralloc_append(out,&ch)) return 0;
59 }
60 if (!stralloc_0(out)) return 0;
61 break;
62
63 case '<': case '>': case ',': case ';': case ':':
64 case '@': case '.':
65 case ' ': case '\t':
66 if (!stralloc_append(out,&ch)) return 0;
67 if (!stralloc_0(out)) return 0;
68 break;
69
70 default:
71 if (!stralloc_append(out,"|")) return 0;
72
73 for (;;) {
74 if (ch == '\\') if (*in) ch = *in++;
75 if (!stralloc_append(out,&ch)) return 0;
76 ch = *in;
77 if (!ch) break;
78 if (ch == '"') break;
79 if (ch == '[') break;
80 if (ch == '(') break;
81 if (ch == '<') break;
82 if (ch == '>') break;
83 if (ch == ',') break;
84 if (ch == ';') break;
85 if (ch == ':') break;
86 if (ch == '@') break;
87 if (ch == '.') break;
88 if (ch == ' ') break;
89 if (ch == '\t') break;
90 ++in;
91 }
92
93 if (!stralloc_0(out)) return 0;
94 break;
95 }
96}
stralloc out
Definition: b64decode.c:12
int mess822_token(stralloc *out, char *in)
Definition: mess822_token.c:5