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
|
const std = @import("std");
const Reader = std.io.AnyReader;
pub fn main() !u8 {
return f();
}
fn f() !u8 {
const file = try std.fs.cwd().openFile("string", .{});
defer file.close();
var br = std.io.bufferedReader(file.reader());
const r = br.reader().any();
var n: u8 = 0;
for (0..1_000_000) |i| {
_ = i;
while (r.readByte() catch null) |c| {
n +%= try f1(r, c);
}
br.start = 0;
br.end = 0;
try file.seekTo(0);
}
return n;
}
fn f1(r: Reader, c1: u8) !u8 {
if (c1 != '\\') return c1;
const c = try r.readByte();
if (c == 'u') return unknown1();
return switch (c) {
'\\', '"' => c,
'0' => 0,
'a' => 7,
'b' => 8,
't' => 9,
'n' => 10,
'v' => 11,
'f' => 12,
'r' => 13,
'e' => 27,
'x' => unknown2(),
else => unknown3(),
};
}
fn f2(r: Reader, c1: u8) !u8 {
if (c1 != '\\') return c1;
const c = try r.readByte();
if (c == 'u') return unknown1();
if (c == 'x') return unknown2();
if (c == '\\' or c == '"') return c;
const itable = .{ '0', 'a', 'b', 't', 'n', 'v', 'f', 'r', 'e' };
const ctable: []const u8 = &.{ 0, 7, 8, 9, 10, 11, 12, 13, 27 };
const i = std.mem.indexOfScalar(u8, &itable, c) orelse return unknown3();
return ctable[i];
}
fn f3(r: Reader, c1: u8) !u8 {
if (c1 != '\\') return c1;
const c = try r.readByte();
if (c == 'u') return unknown1();
if (c == 'x') return unknown2();
if (c == '\\' or c == '"') return c;
if (c == '0') return 0;
const table = comptime t: {
var table: [26]u8 = .{0} ** 26;
table['a' - 'a'] = 7;
table['b' - 'a'] = 8;
table['t' - 'a'] = 9;
table['n' - 'a'] = 10;
table['v' - 'a'] = 11;
table['f' - 'a'] = 12;
table['r' - 'a'] = 13;
table['e' - 'a'] = 27;
break :t table;
};
if (c < 'a') return unknown3();
const result = table[c - 'a'];
return if (result != 0) result else unknown3();
}
fn unknown1() u8 {
return 0;
}
fn unknown2() u8 {
return 0;
}
fn unknown3() u8 {
return 0;
}
|