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


TypeScript strings.startsWith函數代碼示例

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


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

示例1: rgErrorMsgForDisplay

export function rgErrorMsgForDisplay(msg: string): string | undefined {
	const lines = msg.trim().split('\n');
	const firstLine = lines[0].trim();

	if (strings.startsWith(firstLine, 'Error parsing regex')) {
		return firstLine;
	}

	if (strings.startsWith(firstLine, 'regex parse error')) {
		return strings.uppercaseFirstLetter(lines[lines.length - 1].trim());
	}

	if (strings.startsWith(firstLine, 'error parsing glob') ||
		strings.startsWith(firstLine, 'unsupported encoding')) {
		// Uppercase first letter
		return firstLine.charAt(0).toUpperCase() + firstLine.substr(1);
	}

	if (firstLine === `Literal '\\n' not allowed.`) {
		// I won't localize this because none of the Ripgrep error messages are localized
		return `Literal '\\n' currently not supported`;
	}

	if (strings.startsWith(firstLine, 'Literal ')) {
		// Other unsupported chars
		return firstLine;
	}

	return undefined;
}
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:30,代碼來源:fileSearch.ts

示例2: trimTrailingSlash

		.forEach(key => {
			if (excludesToSkip && excludesToSkip.has(key)) {
				return;
			}

			if (!key) {
				return;
			}

			const value = patterns[key];
			key = trimTrailingSlash(folder ? getAbsoluteGlob(folder, key) : key);

			// glob.ts requires forward slashes, but a UNC path still must start with \\
			// #38165 and #38151
			if (strings.startsWith(key, '\\\\')) {
				key = '\\\\' + key.substr(2).replace(/\\/g, '/');
			} else {
				key = key.replace(/\\/g, '/');
			}

			if (typeof value === 'boolean' && value) {
				if (strings.startsWith(key, '\\\\')) {
					// Absolute globs UNC paths don't work properly, see #58758
					key += '**';
				}

				globArgs.push(fixDriveC(key));
			} else if (value && value.when) {
				if (!siblingClauses) {
					siblingClauses = {};
				}

				siblingClauses[key] = value;
			}
		});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:35,代碼來源:ripgrepFileSearch.ts

示例3: resolveContent

	contents.session.protocol.registerBufferProtocol(protocol, (request, callback: any) => {
		if (extensionLocation && extensionLocation.scheme === REMOTE_HOST_SCHEME) {
			const requestUri = URI.parse(request.url);
			const redirectedUri = URI.from({
				scheme: REMOTE_HOST_SCHEME,
				authority: extensionLocation.authority,
				path: '/vscode-resource',
				query: JSON.stringify({
					requestResourcePath: requestUri.path
				})
			});
			resolveContent(fileService, redirectedUri, getMimeType(requestUri), callback);
			return;
		}

		const requestPath = URI.parse(request.url).path;
		const normalizedPath = URI.file(requestPath);
		for (const root of getRoots()) {
			if (startsWith(normalizedPath.fsPath, root.fsPath + sep)) {
				resolveContent(fileService, normalizedPath, getMimeType(normalizedPath), callback);
				return;
			}
		}
		console.error('Webview: Cannot load resource outside of protocol root');
		callback({ error: -10 /* ACCESS_DENIED: https://cs.chromium.org/chromium/src/net/base/net_error_list.h */ });
	}, (error) => {
開發者ID:joelday,項目名稱:vscode,代碼行數:26,代碼來源:webviewProtocols.ts

示例4: assertResolve

	function assertResolve(u1: URI, path: string, expected: URI) {
		const actual = resolvePath(u1, path);
		assertEqualURI(actual, expected, `from ${u1.toString()} and ${path}`);

		if (!isAbsolute(path)) {
			let expectedPath = isWindows ? toSlashes(path) : path;
			expectedPath = startsWith(expectedPath, './') ? expectedPath.substr(2) : expectedPath;
			assert.equal(relativePath(u1, actual), expectedPath, `relativePath (${u1.toString()}) on actual (${actual.toString()}) should be to path (${expectedPath})`);
		}
	}
開發者ID:eamodio,項目名稱:vscode,代碼行數:10,代碼來源:resources.test.ts

示例5: if

		services.forEach((service, index) => {
			let expectedKeyCount = 4;
			let storageToTest;

			const workspaceId = workspaceIds[index];
			if (startsWith(workspaceId, 'file:')) {
				storageToTest = parsed.folder.get(workspaceId);
				expectedKeyCount++; // workspaceIdentifier gets added!
			} else if (startsWith(workspaceId, 'empty:')) {
				storageToTest = parsed.empty.get(workspaceId);
			} else if (startsWith(workspaceId, 'root:')) {
				storageToTest = parsed.multiRoot.get(workspaceId);
			}

			assert.equal(Object.keys(storageToTest).length, expectedKeyCount);
			assert.equal(storageToTest['key1'], service.get('key1', StorageScope.WORKSPACE));
			assert.equal(storageToTest['key2.something'], service.get('key2.something', StorageScope.WORKSPACE));
			assert.equal(storageToTest['key3/special'], service.get('key3/special', StorageScope.WORKSPACE));
			assert.equal(storageToTest['key4 space'], service.get('key4 space', StorageScope.WORKSPACE));
		});
開發者ID:ramesius,項目名稱:vscode,代碼行數:20,代碼來源:migration.test.ts

示例6:

		activeKeys.forEach(key => {
			if (!startsWith(key, workspace.prefix)) {
				return; // not part of workspace prefix or already handled
			}

			activeKeys.delete(key);

			if (workspace.resource === folderId) {
				// storage://workspace/<folder>/someKey => someKey
				const storageKey = key.substr(workspace.prefix.length);
				folderWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		});
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例7: compareByPrefix

export function compareByPrefix(one: string, other: string, lookFor: string): number {
	let elementAName = one.toLowerCase();
	let elementBName = other.toLowerCase();

	// Sort prefix matches over non prefix matches
	let elementAPrefixMatch = strings.startsWith(elementAName, lookFor);
	let elementBPrefixMatch = strings.startsWith(elementBName, lookFor);
	if (elementAPrefixMatch !== elementBPrefixMatch) {
		return elementAPrefixMatch ? -1 : 1;
	}

	// Same prefix: Sort shorter matches to the top to have those on top that match more precisely
	else if (elementAPrefixMatch && elementBPrefixMatch) {
		if (elementAName.length < elementBName.length) {
			return -1;
		}

		if (elementAName.length > elementBName.length) {
			return 1;
		}
	}

	return 0;
}
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:24,代碼來源:comparers.ts

示例8: parseMultiRootStorage

export function parseMultiRootStorage(storage: IStorageLegacy, targetWorkspaceId: string): StorageObject {
	const multiRootStoragePrefix = `${COMMON_WORKSPACE_PREFIX}${targetWorkspaceId}/`;

	const multiRootWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		if (startsWith(key, multiRootStoragePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/root:<id>/someKey => someKey
			multiRootWorkspaceStorage[key.substr(multiRootStoragePrefix.length)] = storage.getItem(key);
		}
	}

	return multiRootWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例9: tab

	public static tab(config: CursorConfiguration, model: ITokenizedModel, cursors: SingleCursorState[]): EditOperationResult {
		let commands: CommandResult[] = [];
		for (let i = 0, len = cursors.length; i < len; i++) {
			const cursor = cursors[i];
			let selection = cursor.selection;

			if (selection.isEmpty()) {

				let lineText = model.getLineContent(selection.startLineNumber);

				if (/^\s*$/.test(lineText)) {
					let goodIndent = this._goodIndentForLine(config, model, selection.startLineNumber);
					goodIndent = goodIndent || '\t';
					let possibleTypeText = config.normalizeIndentation(goodIndent);
					if (!strings.startsWith(lineText, possibleTypeText)) {
						let command = new ReplaceCommand(new Range(selection.startLineNumber, 1, selection.startLineNumber, lineText.length + 1), possibleTypeText);
						commands[i] = new CommandResult(command, true);
						continue;
					}
				}

				commands[i] = new CommandResult(this._replaceJumpToNextIndent(config, model, selection), true);
			} else {
				if (selection.startLineNumber === selection.endLineNumber) {
					let lineMaxColumn = model.getLineMaxColumn(selection.startLineNumber);
					if (selection.startColumn !== 1 || selection.endColumn !== lineMaxColumn) {
						// This is a single line selection that is not the entire line
						commands[i] = new CommandResult(this._replaceJumpToNextIndent(config, model, selection), false);
						continue;
					}
				}

				commands[i] = new CommandResult(
					new ShiftCommand(selection, {
						isUnshift: false,
						tabSize: config.tabSize,
						oneIndent: config.oneIndent,
						useTabStops: config.useTabStops
					}),
					false
				);
			}
		}
		return new EditOperationResult(commands, {
			shouldPushStackElementBefore: true,
			shouldPushStackElementAfter: true
		});
	}
開發者ID:wangcheng678,項目名稱:vscode,代碼行數:48,代碼來源:cursorTypeOperations.ts

示例10: parseNoWorkspaceStorage

export function parseNoWorkspaceStorage(storage: IStorageLegacy) {
	const noWorkspacePrefix = `${StorageLegacyService.WORKSPACE_PREFIX}__$noWorkspace__`;

	const noWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// No Workspace key is for extension development windows
		if (startsWith(key, noWorkspacePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/__$noWorkspace__someKey => someKey
			noWorkspaceStorage[key.substr(NO_WORKSPACE_PREFIX.length)] = storage.getItem(key);
		}
	}

	return noWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:16,代碼來源:


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