當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript strings.rtrim函數代碼示例

本文整理匯總了TypeScript中vs/base/common/strings.rtrim函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript rtrim函數的具體用法?TypeScript rtrim怎麽用?TypeScript rtrim使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了rtrim函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: sanitizeFilePath

export function sanitizeFilePath(candidate: string, cwd: string): string {

	// Special case: allow to open a drive letter without trailing backslash
	if (isWindows && endsWith(candidate, ':')) {
		candidate += sep;
	}

	// Ensure absolute
	if (!isAbsolute(candidate)) {
		candidate = join(cwd, candidate);
	}

	// Ensure normalized
	candidate = normalize(candidate);

	// Ensure no trailing slash/backslash
	if (isWindows) {
		candidate = rtrim(candidate, sep);

		// Special case: allow to open drive root ('C:\')
		if (endsWith(candidate, ':')) {
			candidate += sep;
		}

	} else {
		candidate = rtrim(candidate, sep);

		// Special case: allow to open root ('/')
		if (!candidate) {
			candidate = sep;
		}
	}

	return candidate;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:35,代碼來源:extpath.ts

示例2: relative

export function relative(from: string, to: string): string {
	// ignore trailing slashes
	const originalNormalizedFrom = rtrim(normalize(from), sep);
	const originalNormalizedTo = rtrim(normalize(to), sep);

	// we're assuming here that any non=linux OS is case insensitive
	// so we must compare each part in its lowercase form
	const normalizedFrom = isLinux ? originalNormalizedFrom : originalNormalizedFrom.toLowerCase();
	const normalizedTo = isLinux ? originalNormalizedTo : originalNormalizedTo.toLowerCase();

	const fromParts = normalizedFrom.split(sep);
	const toParts = normalizedTo.split(sep);

	let i = 0, max = Math.min(fromParts.length, toParts.length);

	for (; i < max; i++) {
		if (fromParts[i] !== toParts[i]) {
			break;
		}
	}

	const result = [
		...fill(fromParts.length - i, () => '..'),
		...originalNormalizedTo.split(sep).slice(i)
	];

	return result.join(sep);
}
開發者ID:yuit,項目名稱:vscode,代碼行數:28,代碼來源:paths.ts

示例3: while

		patterns.forEach(pattern => {
			pattern.lastIndex = 0; // the holy grail of software development

			let match: RegExpExecArray | null;
			let offset = 0;
			while ((match = pattern.exec(line)) !== null) {

				// Convert the relative path information to a resource that we can use in links
				const folderRelativePath = strings.rtrim(match[1], '.').replace(/\\/g, '/'); // remove trailing "." that likely indicate end of sentence
				let resourceString: string | undefined;
				try {
					const resource = resourceCreator.toResource(folderRelativePath);
					if (resource) {
						resourceString = resource.toString();
					}
				} catch (error) {
					continue; // we might find an invalid URI and then we dont want to loose all other links
				}

				// Append line/col information to URI if matching
				if (match[3]) {
					const lineNumber = match[3];

					if (match[5]) {
						const columnNumber = match[5];
						resourceString = strings.format('{0}#{1},{2}', resourceString, lineNumber, columnNumber);
					} else {
						resourceString = strings.format('{0}#{1}', resourceString, lineNumber);
					}
				}

				const fullMatch = strings.rtrim(match[0], '.'); // remove trailing "." that likely indicate end of sentence

				const index = line.indexOf(fullMatch, offset);
				offset += index + fullMatch.length;

				const linkRange = {
					startColumn: index + 1,
					startLineNumber: lineIndex,
					endColumn: index + 1 + fullMatch.length,
					endLineNumber: lineIndex
				};

				if (links.some(link => Range.areIntersectingOrTouching(link.range, linkRange))) {
					return; // Do not detect duplicate links
				}

				links.push({
					range: linkRange,
					url: resourceString
				});
			}
		});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:53,代碼來源:outputLinkComputer.ts

示例4: startWatching

	public startWatching(): () => void {
		if (this.contextService.getWorkspace().folders[0].uri.scheme !== Schemas.file) {
			return () => { };
		}
		let basePath: string = normalize(this.contextService.getWorkspace().folders[0].uri.fsPath);

		if (basePath && basePath.indexOf('\\\\') === 0 && endsWith(basePath, sep)) {
			// for some weird reason, node adds a trailing slash to UNC paths
			// we never ever want trailing slashes as our base path unless
			// someone opens root ("/").
			// See also https://github.com/nodejs/io.js/issues/1765
			basePath = rtrim(basePath, sep);
		}

		const watcher = new OutOfProcessWin32FolderWatcher(
			basePath,
			this.ignored,
			events => this.onRawFileEvents(events),
			error => this.onError(error),
			this.verboseLogging
		);

		return () => {
			this.isDisposed = true;
			watcher.dispose();
		};
	}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:27,代碼來源:watcherService.ts

示例5: normalizeGitHubUrl

export function normalizeGitHubUrl(url: string): string {
	// If the url has a .git suffix, remove it
	if (endsWith(url, '.git')) {
		url = url.substr(0, url.length - 4);
	}

	// Remove trailing slash
	url = rtrim(url, '/');

	if (endsWith(url, '/new')) {
		url = rtrim(url, '/new');
	}

	if (endsWith(url, '/issues')) {
		url = rtrim(url, '/issues');
	}

	return url;
}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:19,代碼來源:issueReporterUtil.ts

示例6: preparePath

function preparePath(cwd: string, p: string): string {

	// Trim trailing quotes
	if (platform.isWindows) {
		p = strings.rtrim(p, '"'); // https://github.com/Microsoft/vscode/issues/1498
	}

	// Trim whitespaces
	p = strings.trim(strings.trim(p, ' '), '\t');

	if (platform.isWindows) {

		// Resolve the path against cwd if it is relative
		p = path.resolve(cwd, p);

		// Trim trailing '.' chars on Windows to prevent invalid file names
		p = strings.rtrim(p, '.');
	}

	return p;
}
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:21,代碼來源:paths.ts

示例7: tildify

export function tildify(path: string, userHome: string): string {
	if (isWindows || !path || !userHome) {
		return path; // unsupported
	}

	// Keep a normalized user home path as cache to prevent accumulated string creation
	let normalizedUserHome = normalizedUserHomeCached.original === userHome ? normalizedUserHomeCached.normalized : undefined;
	if (!normalizedUserHome) {
		normalizedUserHome = `${rtrim(userHome, posix.sep)}${posix.sep}`;
		normalizedUserHomeCached = { original: userHome, normalized: normalizedUserHome };
	}

	// Linux: case sensitive, macOS: case insensitive
	if (isLinux ? startsWith(path, normalizedUserHome) : startsWithIgnoreCase(path, normalizedUserHome)) {
		path = `~/${path.substr(normalizedUserHome.length)}`;
	}

	return path;
}
開發者ID:joelday,項目名稱:vscode,代碼行數:19,代碼來源:labels.ts

示例8: constructor

	constructor(
		folders: { path: string, excludes: string[] }[],
		private onFileChanges: (changes: IDiskFileChange[]) => void,
		private errorLogger: (msg: string) => void,
		private verboseLogging: boolean
	) {
		super();

		this.folder = folders[0];

		if (this.folder.path.indexOf('\\\\') === 0 && endsWith(this.folder.path, posix.sep)) {
			// for some weird reason, node adds a trailing slash to UNC paths
			// we never ever want trailing slashes as our base path unless
			// someone opens root ("/").
			// See also https://github.com/nodejs/io.js/issues/1765
			this.folder.path = rtrim(this.folder.path, posix.sep);
		}

		this.startWatching();
	}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:20,代碼來源:watcherService.ts

示例9: normalizeGitHubIssuesUrl

export function normalizeGitHubIssuesUrl(url: string): string {
	// If the url has a .git suffix, remove it
	if (endsWith(url, '.git')) {
		url = url.substr(0, url.length - 4);
	}

	// Remove trailing slash
	url = rtrim(url, '/');

	// If the url already ends with issues/new, it's beautiful, return it
	if (endsWith(url, 'issues/new')) {
		return url;
	}

	// Add new segment if it does not exist
	if (endsWith(url, 'issues')) {
		return url + '/new';
	}

	return url + '/issues/new';
}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:21,代碼來源:issueReporterUtil.ts

示例10: parseStorage

export function parseStorage(storage: IStorage): IParsedStorage {
	const globalStorage = new Map<string, string>();
	const folderWorkspacesStorage = new Map<string /* workspace file resource */, StorageObject>();
	const emptyWorkspacesStorage = new Map<string /* empty workspace id */, StorageObject>();
	const multiRootWorkspacesStorage = new Map<string /* multi root workspace id */, StorageObject>();

	const workspaces: { prefix: string; resource: string; }[] = [];
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// Workspace Storage (storage://workspace/)
		if (startsWith(key, StorageService.WORKSPACE_PREFIX)) {

			// We are looking for key: storage://workspace/<folder>/workspaceIdentifier to be able to find all folder
			// paths that are known to the storage. is the only way how to parse all folder paths known in storage.
			if (endsWith(key, StorageService.WORKSPACE_IDENTIFIER)) {

				// storage://workspace/<folder>/workspaceIdentifier => <folder>/
				let workspace = key.substring(StorageService.WORKSPACE_PREFIX.length, key.length - StorageService.WORKSPACE_IDENTIFIER.length);

				// macOS/Unix: Users/name/folder/
				//    Windows: c%3A/Users/name/folder/
				if (!startsWith(workspace, 'file:')) {
					workspace = `file:///${rtrim(workspace, '/')}`;
				}

				// Windows UNC path: file://localhost/c%3A/Users/name/folder/
				else {
					workspace = rtrim(workspace, '/');
				}

				// storage://workspace/<folder>/workspaceIdentifier => storage://workspace/<folder>/
				const prefix = key.substr(0, key.length - StorageService.WORKSPACE_IDENTIFIER.length);
				workspaces.push({ prefix, resource: workspace });
			}

			// Empty workspace key: storage://workspace/empty:<id>/<key>
			else if (startsWith(key, EMPTY_WORKSPACE_PREFIX)) {

				// storage://workspace/empty:<id>/<key> => <id>
				const emptyWorkspaceId = key.substring(EMPTY_WORKSPACE_PREFIX.length, key.indexOf('/', EMPTY_WORKSPACE_PREFIX.length));
				const emptyWorkspaceResource = URI.from({ path: emptyWorkspaceId, scheme: 'empty' }).toString();

				let emptyWorkspaceStorage = emptyWorkspacesStorage.get(emptyWorkspaceResource);
				if (!emptyWorkspaceStorage) {
					emptyWorkspaceStorage = Object.create(null);
					emptyWorkspacesStorage.set(emptyWorkspaceResource, emptyWorkspaceStorage);
				}

				// storage://workspace/empty:<id>/someKey => someKey
				const storageKey = key.substr(EMPTY_WORKSPACE_PREFIX.length + emptyWorkspaceId.length + 1 /* trailing / */);

				emptyWorkspaceStorage[storageKey] = storage.getItem(key);
			}

			// Multi root workspace key: storage://workspace/root:<id>/<key>
			else if (startsWith(key, MULTI_ROOT_WORKSPACE_PREFIX)) {

				// storage://workspace/root:<id>/<key> => <id>
				const multiRootWorkspaceId = key.substring(MULTI_ROOT_WORKSPACE_PREFIX.length, key.indexOf('/', MULTI_ROOT_WORKSPACE_PREFIX.length));
				const multiRootWorkspaceResource = URI.from({ path: multiRootWorkspaceId, scheme: 'root' }).toString();

				let multiRootWorkspaceStorage = multiRootWorkspacesStorage.get(multiRootWorkspaceResource);
				if (!multiRootWorkspaceStorage) {
					multiRootWorkspaceStorage = Object.create(null);
					multiRootWorkspacesStorage.set(multiRootWorkspaceResource, multiRootWorkspaceStorage);
				}

				// storage://workspace/root:<id>/someKey => someKey
				const storageKey = key.substr(MULTI_ROOT_WORKSPACE_PREFIX.length + multiRootWorkspaceId.length + 1 /* trailing / */);

				multiRootWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		}

		// Global Storage (storage://global)
		else if (startsWith(key, StorageService.GLOBAL_PREFIX)) {

			// storage://global/someKey => someKey
			const globalStorageKey = key.substr(StorageService.GLOBAL_PREFIX.length);
			if (startsWith(globalStorageKey, StorageService.COMMON_PREFIX)) {
				continue; // filter out faulty keys that have the form storage://something/storage://
			}

			globalStorage.set(globalStorageKey, storage.getItem(key));
		}
	}

	// With all the folder paths known we can now extract storage for each path. We have to go through all workspaces
	// from the longest path first to reliably extract the storage. The reason is that one folder path can be a parent
	// of another folder path and as such a simple indexOf check is not enough.
	const workspacesByLength = workspaces.sort((w1, w2) => w1.prefix.length >= w2.prefix.length ? -1 : 1);
	const handledKeys = new Map<string, boolean>();
	workspacesByLength.forEach(workspace => {
		for (let i = 0; i < storage.length; i++) {
			const key = storage.key(i);

			if (handledKeys.has(key) || !startsWith(key, workspace.prefix)) {
				continue; // not part of workspace prefix or already handled
			}
//.........這裏部分代碼省略.........
開發者ID:developers23,項目名稱:vscode,代碼行數:101,代碼來源:migration.ts


注:本文中的vs/base/common/strings.rtrim函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。