forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSplit.ts
More file actions
36 lines (31 loc) · 951 Bytes
/
StringSplit.ts
File metadata and controls
36 lines (31 loc) · 951 Bytes
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
function __TS__StringSplit(this: void, source: string, separator?: string, limit?: number): string[] {
if (limit === undefined) {
limit = 4294967295;
}
if (limit === 0) {
return [];
}
const out = [];
let index = 0;
let count = 0;
if (separator === undefined || separator === "") {
while (index < source.length - 1 && count < limit) {
out[count] = source[index];
count++;
index++;
}
} else {
const separatorLength = separator.length;
let nextIndex = source.indexOf(separator);
while (nextIndex >= 0 && count < limit) {
out[count] = source.substring(index, nextIndex);
count++;
index = nextIndex + separatorLength;
nextIndex = source.indexOf(separator, index);
}
}
if (count < limit) {
out[count] = source.substring(index);
}
return out;
}