1 | /* --------------------------------------------------------------------------------------------
|
2 | * Copyright (c) Remy Suen. All rights reserved.
|
3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | * ------------------------------------------------------------------------------------------ */
|
5 | ;
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.Util = void 0;
|
8 | class Util {
|
9 | static isWhitespace(char) {
|
10 | return char === ' ' || char === '\t' || Util.isNewline(char);
|
11 | }
|
12 | static isNewline(char) {
|
13 | return char === '\r' || char === '\n';
|
14 | }
|
15 | static findLeadingNonWhitespace(content, escapeChar) {
|
16 | whitespaceCheck: for (let i = 0; i < content.length; i++) {
|
17 | switch (content.charAt(i)) {
|
18 | case ' ':
|
19 | case '\t':
|
20 | continue;
|
21 | case escapeChar:
|
22 | escapeCheck: for (let j = i + 1; j < content.length; j++) {
|
23 | switch (content.charAt(j)) {
|
24 | case ' ':
|
25 | case '\t':
|
26 | continue;
|
27 | case '\r':
|
28 | // offset one more for \r\n
|
29 | i = j + 1;
|
30 | continue whitespaceCheck;
|
31 | case '\n':
|
32 | i = j;
|
33 | continue whitespaceCheck;
|
34 | default:
|
35 | break escapeCheck;
|
36 | }
|
37 | }
|
38 | // found an escape character and then reached EOF
|
39 | return -1;
|
40 | default:
|
41 | return i;
|
42 | }
|
43 | }
|
44 | // only possible if the content is the empty string
|
45 | return -1;
|
46 | }
|
47 | /**
|
48 | * Determines if the given position is contained within the given range.
|
49 | *
|
50 | * @param position the position to check
|
51 | * @param range the range to see if the position is inside of
|
52 | */
|
53 | static isInsideRange(position, range) {
|
54 | if (range.start.line === range.end.line) {
|
55 | return range.start.line === position.line
|
56 | && range.start.character <= position.character
|
57 | && position.character <= range.end.character;
|
58 | }
|
59 | else if (range.start.line === position.line) {
|
60 | return range.start.character <= position.character;
|
61 | }
|
62 | else if (range.end.line === position.line) {
|
63 | return position.character <= range.end.character;
|
64 | }
|
65 | return range.start.line < position.line && position.line < range.end.line;
|
66 | }
|
67 | }
|
68 | exports.Util = Util;
|