-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsHex8RGBA.sol
99 lines (84 loc) · 3.02 KB
/
IsHex8RGBA.sol
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
95
96
97
98
99
pragma solidity ^0.4.24;
///@title A test to match 8-digit hexadecimal RGBA colour
///@notice The matches() function tests if argument is an 8-digit hex RGBA colour
///@dev Contract made using https://github.com/gnidan/solregex
///@dev TODO: Remove unnecessary # from regex
///@return bool is/not 8-digit hexadecimal RGBA color
library IsHex8RGBA {
struct State {
bool accepts;
function (byte) pure internal returns (State memory) func;
}
string public constant regex = "#(([0-9a-fA-F]{2}){4})";
function s0(byte c) pure internal returns (State memory) {
c = c;
return State(false, s0);
}
function s1(byte c) pure internal returns (State memory) {
if (c == 35) {
return State(false, s2);
}
return State(false, s0);
}
function s2(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s3);
}
return State(false, s0);
}
function s3(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s4);
}
return State(false, s0);
}
function s4(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s5);
}
return State(false, s0);
}
function s5(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s6);
}
return State(false, s0);
}
function s6(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s7);
}
return State(false, s0);
}
function s7(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s8);
}
return State(false, s0);
}
function s8(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(false, s9);
}
return State(false, s0);
}
function s9(byte c) pure internal returns (State memory) {
if (c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102) {
return State(true, s10);
}
return State(false, s0);
}
function s10(byte c) pure internal returns (State memory) {
// silence unused var warning
c = c;
return State(false, s0);
}
function matches(string input) public pure returns (bool) {
State memory cur = State(false, s1);
for (uint i = 0; i < bytes(input).length; i++) {
byte c = bytes(input)[i];
cur = cur.func(c);
}
return cur.accepts;
}
}