All files / src/utils strings.ts

88% Statements 22/25
70% Branches 7/10
100% Functions 4/4
87.5% Lines 21/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          1x 11x       11x 11x 11x                   1x 111x 111x 97x 14x     14x       1x 102x     1x 1x 1x 5x 2x   5x 5x   1x    
/*---------------------------------------------------------------------------------------------
*  Copyright (c) Microsoft Corporation. All rights reserved.
*  Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
 
export function startsWith(haystack: string, needle: string): boolean {
	Iif (haystack.length < needle.length) {
		return false;
	}
 
	for (let i = 0; i < needle.length; i++) {
		Eif (haystack[i] !== needle[i]) {
			return false;
		}
	}
 
	return true;
}
 
/**
 * Determines if haystack ends with needle.
 */
export function endsWith(haystack: string, needle: string): boolean {
	const diff = haystack.length - needle.length;
	if (diff > 0) {
		return haystack.lastIndexOf(needle) === diff;
	} else Iif (diff === 0) {
		return haystack === needle;
	} else {
		return false;
	}
}
 
export function convertSimple2RegExpPattern(pattern: string): string {
	return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
}
 
export function repeat(value: string, count: number) {
	var s = '';
	while (count > 0) {
		if ((count & 1) === 1) {
			s += value;
		}
		value += value;
		count = count >>> 1;
	}
	return s;
}