Browse Source

Improves splitSingle perf

main
Eric Amodio 1 year ago
parent
commit
ce2761a2a0
1 changed files with 6 additions and 3 deletions
  1. +6
    -3
      src/system/string.ts

+ 6
- 3
src/system/string.ts View File

@ -380,9 +380,12 @@ export function splitLast(s: string, splitter: string) {
}
export function splitSingle(s: string, splitter: string) {
const parts = s.split(splitter, 1);
const first = parts[0];
return first.length === s.length ? parts : [first, s.substr(first.length + 1)];
const index = s.indexOf(splitter);
if (index === -1) return [s];
const start = s.substring(0, index);
const rest = s.substring(index + splitter.length);
return rest != null ? [start, rest] : [start];
}
export function truncate(s: string, truncateTo: number, ellipsis: string = '\u2026', width?: number) {

Loading…
Cancel
Save