-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabowoScriptInterpreter.cs
More file actions
89 lines (70 loc) · 2.61 KB
/
TabowoScriptInterpreter.cs
File metadata and controls
89 lines (70 loc) · 2.61 KB
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
using System.Collections.Generic;
namespace Tabowo.misc
{
public class TabowoScriptInterpreter
{
//version 1.0.0
//Main target: is to use IndexOf() instead of always substring 1 byte
//Maybe this method can be faster than doing this like that: substring for 1 byte at index_position and then check some ifs
public List<string> arguments = new List<string>(); //arguments
public string source; //Text source
public int index = 0; //current interpreter position (to reset simply set to 0)
const int unreachable= 2147483647;
public void Next()
{
// , as arg
// ; as end
// @ as skip
arguments.Clear();
arguments.Add(""); //one for backup
int arg, end, skip;
ushort dec;
while(true)
{
end = source.IndexOf(';', index);
if (end == -1)
{
arguments.Clear();
return; //nothing to do
}
skip = source.IndexOf('@', index);
if (skip == -1) skip = unreachable; //if it is nowhere then set to the unreachable value
arg = source.IndexOf(',', index);
if (arg == -1) arg = unreachable; //same here
dec = Closest(arg, end, skip);
if (dec == 1) //arg
{
Paste(source.Substring(index, arg - index));
arguments.Add(""); //backup
index = arg;
}
else if (dec == 2) //end
{
Paste(source.Substring(index, end - index));
index = end + 1;
return;
}
else if (dec == 3) //skip
{
Paste(source.Substring(index, skip - index) );
Paste(source.Substring(skip+1, 1));
index = skip +1;
}
index++;
}
}
private void Paste(string s)
{
arguments[arguments.Count - 1] += s;
}
//i want to know which number is the closest, i don't want to know the value of the smallest
private ushort Closest(int a,int b,int c)
{
if (a < b)
if (a < c) return 1;
else return 3;
if (b < c) return 2;
return 3;
}
}
}