forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #18871
- Loading branch information
1 parent
e743037
commit 9271136
Showing
14 changed files
with
102 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
export interface SplitLinesOptions { | ||
trim?: boolean; | ||
removeEmptyEntries?: boolean; | ||
} | ||
|
||
/** | ||
* Split a string using the cr and lf characters and return them as an array. | ||
* By default lines are trimmed and empty lines are removed. | ||
* @param {SplitLinesOptions=} splitOptions - Options used for splitting the string. | ||
*/ | ||
export function splitLines( | ||
source: string, | ||
splitOptions: SplitLinesOptions = { removeEmptyEntries: true, trim: true }, | ||
): string[] { | ||
let lines = source.split(/\r?\n/g); | ||
if (splitOptions?.trim) { | ||
lines = lines.map((line) => line.trim()); | ||
} | ||
if (splitOptions?.removeEmptyEntries) { | ||
lines = lines.filter((line) => line.length > 0); | ||
} | ||
return lines; | ||
} | ||
|
||
/** | ||
* Replaces all instances of a substring with a new substring. | ||
*/ | ||
export function replaceAll(source: string, substr: string, newSubstr: string): string { | ||
if (!source) { | ||
return source; | ||
} | ||
|
||
/** Escaping function from the MDN web docs site | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping | ||
* Escapes all the following special characters in a string . * + ? ^ $ { } ( ) | \ \\ | ||
*/ | ||
|
||
function escapeRegExp(unescapedStr: string): string { | ||
return unescapedStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
|
||
return source.replace(new RegExp(escapeRegExp(substr), 'g'), newSubstr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.