Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/doc-explain-ts-code/strings.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CharCode } from './charCode';
7
8
export function getNLines(str: string, n = 1): string {
9
if (n === 0) {
10
return '';
11
}
12
13
let idx = -1;
14
do {
15
idx = str.indexOf('\n', idx + 1);
16
n--;
17
} while (n > 0 && idx >= 0);
18
19
if (idx === -1) {
20
return str;
21
}
22
23
if (str[idx - 1] === '\r') {
24
idx--;
25
}
26
27
return str.substr(0, idx);
28
}
29
30
export function singleLetterHash(n: number): string {
31
const LETTERS_CNT = (CharCode.Z - CharCode.A + 1);
32
33
n = n % (2 * LETTERS_CNT);
34
35
if (n < LETTERS_CNT) {
36
return String.fromCharCode(CharCode.a + n);
37
}
38
39
return String.fromCharCode(CharCode.A + n - LETTERS_CNT);
40
}
41
42