Path: blob/main/extensions/copilot/test/simulation/fixtures/doc-explain-ts-code/strings.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CharCode } from './charCode';67export function getNLines(str: string, n = 1): string {8if (n === 0) {9return '';10}1112let idx = -1;13do {14idx = str.indexOf('\n', idx + 1);15n--;16} while (n > 0 && idx >= 0);1718if (idx === -1) {19return str;20}2122if (str[idx - 1] === '\r') {23idx--;24}2526return str.substr(0, idx);27}2829export function singleLetterHash(n: number): string {30const LETTERS_CNT = (CharCode.Z - CharCode.A + 1);3132n = n % (2 * LETTERS_CNT);3334if (n < LETTERS_CNT) {35return String.fromCharCode(CharCode.a + n);36}3738return String.fromCharCode(CharCode.A + n - LETTERS_CNT);39}404142