refactor(facade): inline StringWrapper (#12051)
This commit is contained in:
@ -137,73 +137,6 @@ export function stringify(token: any): string {
|
||||
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
|
||||
}
|
||||
|
||||
export class StringWrapper {
|
||||
static fromCharCode(code: number): string { return String.fromCharCode(code); }
|
||||
|
||||
static charCodeAt(s: string, index: number): number { return s.charCodeAt(index); }
|
||||
|
||||
static split(s: string, regExp: RegExp): string[] { return s.split(regExp); }
|
||||
|
||||
static equals(s: string, s2: string): boolean { return s === s2; }
|
||||
|
||||
static stripLeft(s: string, charVal: string): string {
|
||||
if (s && s.length) {
|
||||
var pos = 0;
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (s[i] != charVal) break;
|
||||
pos++;
|
||||
}
|
||||
s = s.substring(pos);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static stripRight(s: string, charVal: string): string {
|
||||
if (s && s.length) {
|
||||
var pos = s.length;
|
||||
for (var i = s.length - 1; i >= 0; i--) {
|
||||
if (s[i] != charVal) break;
|
||||
pos--;
|
||||
}
|
||||
s = s.substring(0, pos);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static replace(s: string, from: string, replace: string): string {
|
||||
return s.replace(from, replace);
|
||||
}
|
||||
|
||||
static replaceAll(s: string, from: RegExp, replace: string): string {
|
||||
return s.replace(from, replace);
|
||||
}
|
||||
|
||||
static slice<T>(s: string, from: number = 0, to: number = null): string {
|
||||
return s.slice(from, to === null ? undefined : to);
|
||||
}
|
||||
|
||||
static replaceAllMapped(s: string, from: RegExp, cb: (m: string[]) => string): string {
|
||||
return s.replace(from, function(...matches: any[]) {
|
||||
// Remove offset & string from the result array
|
||||
matches.splice(-2, 2);
|
||||
// The callback receives match, p1, ..., pn
|
||||
return cb(matches);
|
||||
});
|
||||
}
|
||||
|
||||
static contains(s: string, substr: string): boolean { return s.indexOf(substr) != -1; }
|
||||
|
||||
static compare(a: string, b: string): number {
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else if (a > b) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class StringJoiner {
|
||||
constructor(public parts: string[] = []) {}
|
||||
|
||||
|
Reference in New Issue
Block a user