-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.dm
62 lines (51 loc) · 1.48 KB
/
utility.dm
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
// A robust text2list implementation that doesn't error on odd strings
// and has the default option of skipping empty additions.
proc/__textToList(str, delim = ";", skip_empty = TRUE) {
if(!str) {
return new /list();
}
var/next = findtext(str, delim);
var/last = 0;
. = new /list();;
while(next != 0) {
var/txt = copytext(str, last+1, next);
if(skip_empty == FALSE || txt) {
. += txt;
}
last = next;
next = findtext(str, delim, next+1, 0);
}
var/txt = copytext(str, last+1);
if(skip_empty == FALSE || txt) {
. += txt;
}
}
// A robust list2text implementation that can skip empty entries.
proc/__listToText(list/L, delim = ";", skip_empty = TRUE) {
if(!L || !length(L)) return "";
. = "";
for(var/entry in L) {
if(skip_empty == FALSE || entry) {
. = "[.][entry][delim]";
}
}
if(skip_empty != FALSE) . = copytext(., 1, length(.) - length(delim) + 1);
}
proc/__replaceText(str, replace, with) {
return __listToText(__textToList(str, replace, FALSE), with, FALSE);
}
proc/__textMatch(text, attempt, case = FALSE, partial = TRUE) {
var/match = text;
if(!case) {
attempt = lowertext(attempt);
match = lowertext(match);
}
if(partial) return (attempt == match || copytext(match, 1, length(attempt)+1) == attempt);
else return (attempt == match);
}
proc/__isAlpha(ascii) {
return ((ascii >= 65 && ascii <= 90) || (ascii >= 97 && ascii <= 122))
}
proc/__isTextNum(n) {
return ("[text2num(n)]" == "[n]");
}