65
66
constructor(edges: Edge[]) {
68
>
let maxState = State.Invalid;
69
>
for (let i = 0, len = edges.length; i < len; i++) {
70
>
const [from, chCode, to] = edges[i];
71
>
if (chCode > maxCharCode) {
72
>
maxCharCode = chCode;
73
>
}
74
>
if (from > maxState) {
75
>
maxState = from;
76
>
}
77
>
if (to > maxState) {
78
>
maxState = to;
79
>
}
80
>
}
81
>
82
>
maxCharCode++;
83
>
maxState++;
84
>
85
>
const states = new Uint8Matrix(maxState, maxCharCode, State.Invalid);
86
>
for (let i = 0, len = edges.length; i < len; i++) {
87
>
const [from, chCode, to] = edges[i];
88
>
states.set(from, chCode, to);
89
>
}
90
>
91
>
this._states = states;
92
>
this._maxCharCode = maxCharCode;
93
>
}
94
95
public nextState(currentState: State, chCode: number): State {
97
return State.Invalid;
98
}
100
>
}
101
}
102
103
// State machine for http:// or https:// or file://
104
let _stateMachine: StateMachine | null = null;
106
>
if (_stateMachine === null) {
107
>
_stateMachine = new StateMachine([
108
>
[State.Start, CharCode.h, State.H],
109
>
[State.Start, CharCode.H, State.H],
110
>
[State.Start, CharCode.f, State.F],
111
>
[State.Start, CharCode.F, State.F],
112
>
113
>
[State.H, CharCode.t, State.HT],
114
>
[State.H, CharCode.T, State.HT],
115
>
116
>
[State.HT, CharCode.t, State.HTT],
117
>
[State.HT, CharCode.T, State.HTT],
118
>
119
>
[State.HTT, CharCode.p, State.HTTP],
120
>
[State.HTT, CharCode.P, State.HTTP],
121
>
122
>
[State.HTTP, CharCode.s, State.BeforeColon],
123
>
[State.HTTP, CharCode.S, State.BeforeColon],
124
>
[State.HTTP, CharCode.Colon, State.AfterColon],
125
>
126
>
[State.F, CharCode.i, State.FI],
127
>
[State.F, CharCode.I, State.FI],
128
>
129
>
[State.FI, CharCode.l, State.FIL],
130
>
[State.FI, CharCode.L, State.FIL],
131
>
132
>
[State.FIL, CharCode.e, State.BeforeColon],
133
>
[State.FIL, CharCode.E, State.BeforeColon],
134
>
135
>
[State.BeforeColon, CharCode.Colon, State.AfterColon],
136
>
137
>
[State.AfterColon, CharCode.Slash, State.AlmostThere],
138
>
139
>
[State.AlmostThere, CharCode.Slash, State.End],
140
>
]);
141
>
}
142
>
return _stateMachine;
143
>
}
144
145