2 /*---------------------------------------------------------------------------------------------
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
4 * Licensed under the MIT License. See License.txt in the project root for license information.
\r
5 *--------------------------------------------------------------------------------------------*/
\r
6 Object.defineProperty(exports, "__esModule", { value: true });
\r
7 exports.joinPath = exports.normalizePath = exports.resolvePath = exports.isAbsolutePath = exports.extname = exports.basename = exports.dirname = exports.getScheme = void 0;
\r
8 const vscode_uri_1 = require("vscode-uri");
\r
9 function getScheme(uri) {
\r
10 return uri.substr(0, uri.indexOf(':'));
\r
12 exports.getScheme = getScheme;
\r
13 function dirname(uri) {
\r
14 const lastIndexOfSlash = uri.lastIndexOf('/');
\r
15 return lastIndexOfSlash !== -1 ? uri.substr(0, lastIndexOfSlash) : '';
\r
17 exports.dirname = dirname;
\r
18 function basename(uri) {
\r
19 const lastIndexOfSlash = uri.lastIndexOf('/');
\r
20 return uri.substr(lastIndexOfSlash + 1);
\r
22 exports.basename = basename;
\r
23 const Slash = '/'.charCodeAt(0);
\r
24 const Dot = '.'.charCodeAt(0);
\r
25 function extname(uri) {
\r
26 for (let i = uri.length - 1; i >= 0; i--) {
\r
27 const ch = uri.charCodeAt(i);
\r
29 if (i > 0 && uri.charCodeAt(i - 1) !== Slash) {
\r
30 return uri.substr(i);
\r
36 else if (ch === Slash) {
\r
42 exports.extname = extname;
\r
43 function isAbsolutePath(path) {
\r
44 return path.charCodeAt(0) === Slash;
\r
46 exports.isAbsolutePath = isAbsolutePath;
\r
47 function resolvePath(uriString, path) {
\r
48 if (isAbsolutePath(path)) {
\r
49 const uri = vscode_uri_1.URI.parse(uriString);
\r
50 const parts = path.split('/');
\r
51 return uri.with({ path: normalizePath(parts) }).toString();
\r
53 return joinPath(uriString, path);
\r
55 exports.resolvePath = resolvePath;
\r
56 function normalizePath(parts) {
\r
57 const newParts = [];
\r
58 for (const part of parts) {
\r
59 if (part.length === 0 || part.length === 1 && part.charCodeAt(0) === Dot) {
\r
62 else if (part.length === 2 && part.charCodeAt(0) === Dot && part.charCodeAt(1) === Dot) {
\r
66 newParts.push(part);
\r
69 if (parts.length > 1 && parts[parts.length - 1].length === 0) {
\r
72 let res = newParts.join('/');
\r
73 if (parts[0].length === 0) {
\r
78 exports.normalizePath = normalizePath;
\r
79 function joinPath(uriString, ...paths) {
\r
80 const uri = vscode_uri_1.URI.parse(uriString);
\r
81 const parts = uri.path.split('/');
\r
82 for (let path of paths) {
\r
83 parts.push(...path.split('/'));
\r
85 return uri.with({ path: normalizePath(parts) }).toString();
\r
87 exports.joinPath = joinPath;
\r
88 //# sourceMappingURL=requests.js.map