-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathextString.sc
More file actions
61 lines (52 loc) · 1.62 KB
/
extString.sc
File metadata and controls
61 lines (52 loc) · 1.62 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
+String {
urlDecode {
var str = this;
str.findRegexp("%[A-Fa-f0-9]{2}").collect({
|found|
var ch = found[1][1..];
ch = (ch[0].digit << 4) | ch[1].digit;
[found[0], ch]
}).reverseDo {
|replace|
str = str[0..(replace[0]-1)]
++ replace[1].asAscii
++ str[(replace[0] + 3)..]
};
^str
}
lineCharToIndex {
|line, character|
var currentIndex = 0;
line.do {
currentIndex = this.find("\n", false, currentIndex);
if (currentIndex.isNil) {
^this.size
} {
currentIndex = currentIndex + 1
}
};
^(currentIndex + character)
}
// Given an absolute file path in OSX, Windows, or Linux format, return a file URI
// that will be understood by the LSP client.
pathToFileURI {
^Platform.case(
\osx, { "file://" ++ this },
\windows, { "file:///" ++ this.replace("\\", "/") },
\linux, { "file://" ++ this },
{ "file://" ++ this }
)
}
/*
Reverse of pathToFileURI - given a file URI, returns a path in the format of the
current OS.
*/
fileURIToPath {
^(Platform.case(
\osx, { this.replace("file://", "") },
\windows, { this.replace("file:///", "").replace("/", "\\") },
\linux, { this.replace("file://", "") },
{ this.replace("file://", "") }
).urlDecode)
}
}