-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.uc
More file actions
executable file
·50 lines (50 loc) · 1.86 KB
/
Copy pathutils.uc
File metadata and controls
executable file
·50 lines (50 loc) · 1.86 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
export function utf8validCopy(input)
{
if (input === null) {
return null;
}
let output = "";
for (let i = 0; i < length(input); ) {
const b0 = ord(input, i++);
switch (b0 & 0xC0) {
case 0x00:
case 0x40:
output += uchr(b0);
break;
case 0x80:
for (; (ord(input, i) & 0xC0) === 0x80; i++); // Error - resync
break;
case 0xC0:
const b1 = ord(input, i++);
if ((b1 & 0xC0) !== 0x80) {
for (; (ord(input, i) & 0xC0) === 0x80; i++); // Error - resync
}
else if ((b0 & 0xE0) === 0xE0) {
const b2 = ord(input, i++);
if ((b2 & 0xC0) !== 0x80) {
for (; (ord(input, i) & 0xC0) === 0x80; i++); // Error - resync
}
else if ((b0 & 0xF0) === 0xF0) {
const b3 = ord(input, i++);
if ((b3 & 0xC0) !== 0x80) {
for (; (ord(input, i) & 0xC0) === 0x80; i++); // Error - resync
}
else if ((b0 & 0xF8) === 0xF8) {
for (; (ord(input, i) & 0xC0) === 0x80; i++); // Error - resync
}
else {
output += uchr(((b0 & 0x07) << 18) | ((b1 & 0x3F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
}
}
else {
output += uchr(((b0 & 0x0F) << 12) | ((b1 & 0x3F) << 6) | (b2 & 0x3F));
}
}
else {
output += uchr(((b0 & 0x1F) << 6) | (b1 & 0x3F));
}
break;
}
}
return output;
};