mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-07 01:25:38 -05:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
export function startsWith(haystack: string, needle: string): boolean {
|
|
if (haystack.length < needle.length) {
|
|
return false;
|
|
}
|
|
|
|
for (let i = 0; i < needle.length; i++) {
|
|
if (haystack[i] !== needle[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determines if haystack ends with needle.
|
|
*/
|
|
export function endsWith(haystack: string, needle: string): boolean {
|
|
let diff = haystack.length - needle.length;
|
|
if (diff > 0) {
|
|
return haystack.lastIndexOf(needle) === diff;
|
|
} else if (diff === 0) {
|
|
return haystack === needle;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function convertSimple2RegExpPattern(pattern: string): string {
|
|
return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
|
|
}
|