generated from WillAbides/goproject-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 6
/
misc_machines.rl
94 lines (81 loc) · 2.37 KB
/
misc_machines.rl
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
87
88
89
90
91
92
93
94
package rjson
func unescapeStringContent(data []byte, dst []byte) ([]byte, int, error) {
cs, p := 0, 0
pe := len(data)
eof := len(data)
var segStart int
dst = growBytesSliceCapacity(dst, len(dst) + len(data))
var unescapeUnicodeCharBytes int
var ok bool
%%{
machine unescapeStringContent;
include common "common.rl";
main :=
(
(
not_double_quote_or_escape >{segStart = p} %{dst = append(dst, data[segStart:p] ...)}
| '\\"' @{dst = append(dst, '"')}
| '\\\\' @{dst = append(dst, '\\')}
| '\\/' @{dst = append(dst, '/')}
| '\\\'' @{dst = append(dst, '\'')}
| '\\b' @{dst = append(dst, '\b')}
| '\\f' @{dst = append(dst, '\f')}
| '\\n' @{dst = append(dst, '\n')}
| '\\r' @{dst = append(dst, '\r')}
| '\\t' @{dst = append(dst, '\t')}
| escaped_unicode >{ segStart = p } @{
dst, unescapeUnicodeCharBytes, ok = unescapeUnicodeChar(data[segStart:], dst)
if !ok {
return nil, p, errUnexpectedByteInString(data[p])
}
if unescapeUnicodeCharBytes > 6 {
p += unescapeUnicodeCharBytes - 6
}
}
)*) @err{
return nil, p, errInvalidString
};
write data; write init; write exec;
}%%
return dst, p,nil
}
func appendRemainderOfString(data []byte, dst []byte) ([]byte, int, error) {
cs, p := 0, 0
pe := len(data)
eof := len(data)
var segStart int
dst = growBytesSliceCapacity(dst, len(dst) + len(data))
var unescapeUnicodeCharBytes int
var ok bool
%%{
machine appendRemainderOfString;
include common "common.rl";
main :=
(
(
not_double_quote_or_escape >{segStart = p} %{dst = append(dst, data[segStart:p] ...)}
| '\\"' @{dst = append(dst, '"')}
| '\\\\' @{dst = append(dst, '\\')}
| '\\/' @{dst = append(dst, '/')}
| '\\b' @{dst = append(dst, '\b')}
| '\\f' @{dst = append(dst, '\f')}
| '\\n' @{dst = append(dst, '\n')}
| '\\r' @{dst = append(dst, '\r')}
| '\\t' @{dst = append(dst, '\t')}
| escaped_unicode >{ segStart = p } @{
dst, unescapeUnicodeCharBytes, ok = unescapeUnicodeChar(data[segStart:], dst)
if !ok {
return nil, p, errUnexpectedByteInString(data[p])
}
if unescapeUnicodeCharBytes > 6 {
p += unescapeUnicodeCharBytes - 6
}
}
)*
double_quote) @err{
return nil, p, errInvalidString
};
write data; write init; write exec;
}%%
return dst, p,nil
}