1 /*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
5 export function startsWith(haystack, needle) {
6 if (haystack.length < needle.length) {
9 for (var i = 0; i < needle.length; i++) {
10 if (haystack[i] !== needle[i]) {
17 * Determines if haystack ends with needle.
19 export function endsWith(haystack, needle) {
20 var diff = haystack.length - needle.length;
22 return haystack.lastIndexOf(needle) === diff;
24 else if (diff === 0) {
25 return haystack === needle;
31 export function convertSimple2RegExpPattern(pattern) {
32 return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
34 export function repeat(value, count) {
37 if ((count & 1) === 1) {
45 export function extendedRegExp(pattern) {
46 if (startsWith(pattern, '(?i)')) {
47 return new RegExp(pattern.substring(4), 'i');
50 return new RegExp(pattern);