v2 / vlib / v / fmt / tests / match_with_multi_commented_branches_keep.vv
40 lines · 38 sloc · 639 bytes · 373da7779250a8da60cd4f499a043e944a31ef7c
Raw
1import strings
2
3fn escape_string(s string) string {
4 mut res := strings.new_builder(s.len * 2)
5 for ch in s {
6 match ch {
7 0 // NUL (null)
8 {
9 res.write_u8(92) // \
10 res.write_u8(48) // 0
11 }
12 10 { // LF (line feed)
13 res.write_u8(92) // \
14 res.write_u8(110) // n
15 }
16 13 { // CR (carriage return)
17 res.write_u8(92) // \
18 res.write_u8(114) // r
19 }
20 26 { // SUB (substitute)
21 res.write_u8(92) // \
22 res.write_u8(90) // Z
23 }
24 34, // "
25 39, // '
26 92 // \
27 {
28 res.write_u8(92) // \
29 res.write_u8(ch)
30 }
31 else {
32 res.write_u8(ch)
33 }
34 }
35 }
36 return res.bytestr()
37}
38
39fn main() {
40}
41