-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathoptions.bal
40 lines (35 loc) · 1.05 KB
/
options.bal
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
const LOWER = "abcdefghijklmnopqrstuvwxyz";
const UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string VALID_GC_NAME_CHARS = LOWER + UPPER + "-_";
public const DEBUG_NONE = 0;
public const DEBUG_BACKTRACE = 1;
public const DEBUG_FULL = 2;
public type DebugLevel DEBUG_NONE|DEBUG_BACKTRACE|DEBUG_FULL;
public type Options record {|
string? gcName = ();
DebugLevel debugLevel = DEBUG_BACKTRACE;
|};
public function validGcName(string? gcName) returns string?|error {
if gcName == () {
return ();
}
else {
foreach var c in gcName {
if !VALID_GC_NAME_CHARS.includes(c) {
return error("invalid gc name " + gcName);
}
}
return gcName;
}
}
public function validDebugLevel(int? debugLevel) returns DebugLevel|error {
if (debugLevel == ()) {
return DEBUG_BACKTRACE;
}
else if (debugLevel < DEBUG_NONE || debugLevel > DEBUG_FULL) {
return error("invalid debug level " + debugLevel.toString());
}
else {
return <DebugLevel>debugLevel;
}
}