1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | exports.compareSubstringIgnoreCase = exports.compareIgnoreCase = exports.compareSubstring = exports.compare = exports.unescapeInvisibleChars = exports.escapeInvisibleChars = exports.split = exports.startsWithIgnoreCase = exports.escapeRegExpCharacters = exports.commonPrefixLength = exports.equalsIgnoreCase = exports.isUpperAsciiLetter = exports.isLowerAsciiLetter = exports.endsWith = void 0;
|
23 |
|
24 |
|
25 |
|
26 | function endsWith(haystack, needle) {
|
27 | const diff = haystack.length - needle.length;
|
28 | if (diff > 0) {
|
29 | return haystack.indexOf(needle, diff) === diff;
|
30 | }
|
31 | else if (diff === 0) {
|
32 | return haystack === needle;
|
33 | }
|
34 | else {
|
35 | return false;
|
36 | }
|
37 | }
|
38 | exports.endsWith = endsWith;
|
39 | function isLowerAsciiLetter(code) {
|
40 | return code >= 97 && code <= 122 ;
|
41 | }
|
42 | exports.isLowerAsciiLetter = isLowerAsciiLetter;
|
43 | function isUpperAsciiLetter(code) {
|
44 | return code >= 65 && code <= 90 ;
|
45 | }
|
46 | exports.isUpperAsciiLetter = isUpperAsciiLetter;
|
47 | function isAsciiLetter(code) {
|
48 | return isLowerAsciiLetter(code) || isUpperAsciiLetter(code);
|
49 | }
|
50 | function equalsIgnoreCase(a, b) {
|
51 | const len1 = a ? a.length : 0;
|
52 | const len2 = b ? b.length : 0;
|
53 | if (len1 !== len2) {
|
54 | return false;
|
55 | }
|
56 | return doEqualsIgnoreCase(a, b);
|
57 | }
|
58 | exports.equalsIgnoreCase = equalsIgnoreCase;
|
59 | function doEqualsIgnoreCase(a, b, stopAt = a.length) {
|
60 | if (typeof a !== 'string' || typeof b !== 'string') {
|
61 | return false;
|
62 | }
|
63 | for (let i = 0; i < stopAt; i++) {
|
64 | const codeA = a.charCodeAt(i);
|
65 | const codeB = b.charCodeAt(i);
|
66 | if (codeA === codeB) {
|
67 | continue;
|
68 | }
|
69 |
|
70 | if (isAsciiLetter(codeA) && isAsciiLetter(codeB)) {
|
71 | const diff = Math.abs(codeA - codeB);
|
72 | if (diff !== 0 && diff !== 32) {
|
73 | return false;
|
74 | }
|
75 | }
|
76 |
|
77 |
|
78 | else {
|
79 | if (String.fromCharCode(codeA).toLowerCase() !== String.fromCharCode(codeB).toLowerCase()) {
|
80 | return false;
|
81 | }
|
82 | }
|
83 | }
|
84 | return true;
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | function commonPrefixLength(a, b) {
|
90 | let i;
|
91 | const len = Math.min(a.length, b.length);
|
92 | for (i = 0; i < len; i++) {
|
93 | if (a.charCodeAt(i) !== b.charCodeAt(i)) {
|
94 | return i;
|
95 | }
|
96 | }
|
97 | return len;
|
98 | }
|
99 | exports.commonPrefixLength = commonPrefixLength;
|
100 |
|
101 |
|
102 |
|
103 | function escapeRegExpCharacters(value) {
|
104 | return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\[\]\(\)\#]/g, '\\$&');
|
105 | }
|
106 | exports.escapeRegExpCharacters = escapeRegExpCharacters;
|
107 | function startsWithIgnoreCase(str, candidate) {
|
108 | const candidateLength = candidate.length;
|
109 | if (candidate.length > str.length) {
|
110 | return false;
|
111 | }
|
112 | return doEqualsIgnoreCase(str, candidate, candidateLength);
|
113 | }
|
114 | exports.startsWithIgnoreCase = startsWithIgnoreCase;
|
115 | function* split(s, splitter) {
|
116 | let start = 0;
|
117 | while (start < s.length) {
|
118 | let end = s.indexOf(splitter, start);
|
119 | if (end === -1) {
|
120 | end = s.length;
|
121 | }
|
122 | yield s.substring(start, end);
|
123 | start = end + splitter.length;
|
124 | }
|
125 | }
|
126 | exports.split = split;
|
127 | function escapeInvisibleChars(value) {
|
128 | return value.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
129 | }
|
130 | exports.escapeInvisibleChars = escapeInvisibleChars;
|
131 | function unescapeInvisibleChars(value) {
|
132 | return value.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
|
133 | }
|
134 | exports.unescapeInvisibleChars = unescapeInvisibleChars;
|
135 | function compare(a, b) {
|
136 | if (a < b) {
|
137 | return -1;
|
138 | }
|
139 | else if (a > b) {
|
140 | return 1;
|
141 | }
|
142 | else {
|
143 | return 0;
|
144 | }
|
145 | }
|
146 | exports.compare = compare;
|
147 | function compareSubstring(a, b, aStart = 0, aEnd = a.length, bStart = 0, bEnd = b.length) {
|
148 | for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) {
|
149 | const codeA = a.charCodeAt(aStart);
|
150 | const codeB = b.charCodeAt(bStart);
|
151 | if (codeA < codeB) {
|
152 | return -1;
|
153 | }
|
154 | else if (codeA > codeB) {
|
155 | return 1;
|
156 | }
|
157 | }
|
158 | const aLen = aEnd - aStart;
|
159 | const bLen = bEnd - bStart;
|
160 | if (aLen < bLen) {
|
161 | return -1;
|
162 | }
|
163 | else if (aLen > bLen) {
|
164 | return 1;
|
165 | }
|
166 | return 0;
|
167 | }
|
168 | exports.compareSubstring = compareSubstring;
|
169 | function compareIgnoreCase(a, b) {
|
170 | return compareSubstringIgnoreCase(a, b, 0, a.length, 0, b.length);
|
171 | }
|
172 | exports.compareIgnoreCase = compareIgnoreCase;
|
173 | function compareSubstringIgnoreCase(a, b, aStart = 0, aEnd = a.length, bStart = 0, bEnd = b.length) {
|
174 | for (; aStart < aEnd && bStart < bEnd; aStart++, bStart++) {
|
175 | const codeA = a.charCodeAt(aStart);
|
176 | const codeB = b.charCodeAt(bStart);
|
177 | if (codeA === codeB) {
|
178 |
|
179 | continue;
|
180 | }
|
181 | const diff = codeA - codeB;
|
182 | if (diff === 32 && isUpperAsciiLetter(codeB)) {
|
183 | continue;
|
184 | }
|
185 | else if (diff === -32 && isUpperAsciiLetter(codeA)) {
|
186 | continue;
|
187 | }
|
188 | if (isLowerAsciiLetter(codeA) && isLowerAsciiLetter(codeB)) {
|
189 |
|
190 | return diff;
|
191 | }
|
192 | else {
|
193 | return compareSubstring(a.toLowerCase(), b.toLowerCase(), aStart, aEnd, bStart, bEnd);
|
194 | }
|
195 | }
|
196 | const aLen = aEnd - aStart;
|
197 | const bLen = bEnd - bStart;
|
198 | if (aLen < bLen) {
|
199 | return -1;
|
200 | }
|
201 | else if (aLen > bLen) {
|
202 | return 1;
|
203 | }
|
204 | return 0;
|
205 | }
|
206 | exports.compareSubstringIgnoreCase = compareSubstringIgnoreCase;
|
207 |
|
\ | No newline at end of file |