resources.ts 1.3 KB
Newer Older
I
isidor 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import * as paths from 'vs/base/common/paths';
import uri from 'vs/base/common/uri';
9
import { equalsIgnoreCase } from 'vs/base/common/strings';
I
isidor 已提交
10

I
isidor 已提交
11 12
export function basenameOrAuthority(resource: uri): string {
	return paths.basename(resource.fsPath) || resource.authority;
I
isidor 已提交
13
}
I
isidor 已提交
14 15 16 17 18 19 20 21

export function isEqualOrParent(first: uri, second: uri, ignoreCase?: boolean): boolean {
	if (first.scheme === second.scheme && first.authority === second.authority) {
		return paths.isEqualOrParent(first.fsPath, second.fsPath, ignoreCase);
	}

	return false;
}
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
export function isEqual(first: uri, second: uri, ignoreCase?: boolean): boolean {
	const identityEquals = (first === second);
	if (identityEquals) {
		return true;
	}

	if (!first || !second) {
		return false;
	}

	if (ignoreCase) {
		return equalsIgnoreCase(first.toString(), second.toString());
	}

	return first.toString() === second.toString();
}

40 41 42 43 44
export function dirname(resource: uri): uri {
	return resource.with({
		path: paths.dirname(resource.path)
	});
}