blob: fb9be3695f223f88d537b799d4b40be393bb9124 (
plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
package bjc.everge;
/**
* Represents a string with a set of control flags attached to it.
*
* @author Ben Culkin
*/
public class ControlledString {
/**
* Represents a single control (a key-values pair)
*
* @author Ben Culkin
*/
public static class Control {
/**
* The name of the control.
*/
public String name;
/**
* The arguments to the control.
*/
public String[] args;
/**
* Create a new blank control.
*/
public Control() {
}
/**
* Create a new argless control.
*
* @param nam
* The name of the control.
*/
public Control(String nam) {
name = nam;
}
/**
* Create a new control.
*
* @param nam
* The name of the control.
* @param args
* The arguments of the control.
*/
public Control(String nam, String... ars) {
name = nam;
args = ars;
}
}
/**
* The string the controls apply to.
*/
public String strang;
/**
* The controls that apply to the string.
*/
public Control[] controls;
/**
* Create a new blank controlled string.
*/
public ControlledString() {
controls = new Control[0];
}
/**
* Create a new controlled string without any controls.
*
* @param strung
* The string to use.
*/
public ControlledString(String strung) {
strang = strung;
controls = new Control[0];
}
/**
* Create a new controlled string.
*
* @param strung
* The string to use.
* @param controls
* The controls that apply to the string.
*/
public ControlledString(String strung, Control... controls) {
strang = strung;
controls = controls;
}
/**
* Check if the string has controls.
*
* @return Whether or not the string has controls.
*/
public boolean hasControls() {
return controls.length > 0;
}
/**
* Parse a controlled string from a regular string.
*
* The controls must be parsed from the beginning of the string, and are indicated by occurances
* of contInd that bracket them from the string. The individual controls are delimited by
* instances of contSep, with arguments to them being separated by occurances of contArg.
*
* Each of those separators (which must be regular strings, not regexes or anything) may be
* escaped by preceeding them with a copy of contEsc.
*
* @param lne
* The string to parse frmo.
* @param contInd
* The indicator for whether or not there are controls.
* @param contSep
* The separator of individual controls.
* @param contArg
* The separator of control arguments.
* @param contEsc
* The escape string for each of the separators/indicators.
*
* @return A parsed control string.
*/
public static ControlledString parse(String lne, String contInd, String contSep,
String contArg, String contEsc) {
ControlledString cs = new ControlledString(lne);
return cs;
}
}
|