Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/css-language-features/client/src/dropOrPaste/uriList.ts
3321 views
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
6
import * as vscode from 'vscode';
7
8
function splitUriList(str: string): string[] {
9
return str.split('\r\n');
10
}
11
12
function parseUriList(str: string): string[] {
13
return splitUriList(str)
14
.filter(value => !value.startsWith('#')) // Remove comments
15
.map(value => value.trim());
16
}
17
18
export class UriList {
19
20
static from(str: string): UriList {
21
return new UriList(coalesce(parseUriList(str).map(line => {
22
try {
23
return { uri: vscode.Uri.parse(line), str: line };
24
} catch {
25
// Uri parse failure
26
return undefined;
27
}
28
})));
29
}
30
31
constructor(
32
public readonly entries: ReadonlyArray<{ readonly uri: vscode.Uri; readonly str: string }>
33
) { }
34
}
35
36
function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
37
return <T[]>array.filter(e => !!e);
38
}
39
40