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