rregex 1.7.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -47
- package/lib/browser.d.ts +790 -278
- package/lib/browser.js +649 -179
- package/lib/commonjs.d.ts +779 -271
- package/lib/commonjs.js +659 -182
- package/lib/module.d.ts +779 -271
- package/lib/module.js +656 -179
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +15 -11
- package/lib/types.d.ts +790 -278
- package/package.json +23 -2
package/lib/commonjs.js
CHANGED
|
@@ -7,10 +7,19 @@ const heap = new Array(128).fill(undefined);
|
|
|
7
7
|
|
|
8
8
|
heap.push(undefined, null, true, false);
|
|
9
9
|
|
|
10
|
-
function getObject(idx) { return heap[idx]; }
|
|
11
|
-
|
|
12
10
|
let heap_next = heap.length;
|
|
13
11
|
|
|
12
|
+
function addHeapObject(obj) {
|
|
13
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
14
|
+
const idx = heap_next;
|
|
15
|
+
heap_next = heap[idx];
|
|
16
|
+
|
|
17
|
+
heap[idx] = obj;
|
|
18
|
+
return idx;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getObject(idx) { return heap[idx]; }
|
|
22
|
+
|
|
14
23
|
function dropObject(idx) {
|
|
15
24
|
if (idx < 132) return;
|
|
16
25
|
heap[idx] = heap_next;
|
|
@@ -41,15 +50,6 @@ function getStringFromWasm0(ptr, len) {
|
|
|
41
50
|
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
function addHeapObject(obj) {
|
|
45
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
46
|
-
const idx = heap_next;
|
|
47
|
-
heap_next = heap[idx];
|
|
48
|
-
|
|
49
|
-
heap[idx] = obj;
|
|
50
|
-
return idx;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
53
|
let WASM_VECTOR_LEN = 0;
|
|
54
54
|
|
|
55
55
|
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
@@ -118,69 +118,24 @@ function getInt32Memory0() {
|
|
|
118
118
|
return cachedInt32Memory0;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
if (type == 'string') {
|
|
128
|
-
return `"${val}"`;
|
|
129
|
-
}
|
|
130
|
-
if (type == 'symbol') {
|
|
131
|
-
const description = val.description;
|
|
132
|
-
if (description == null) {
|
|
133
|
-
return 'Symbol';
|
|
134
|
-
} else {
|
|
135
|
-
return `Symbol(${description})`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (type == 'function') {
|
|
139
|
-
const name = val.name;
|
|
140
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
141
|
-
return `Function(${name})`;
|
|
142
|
-
} else {
|
|
143
|
-
return 'Function';
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// objects
|
|
147
|
-
if (Array.isArray(val)) {
|
|
148
|
-
const length = val.length;
|
|
149
|
-
let debug = '[';
|
|
150
|
-
if (length > 0) {
|
|
151
|
-
debug += debugString(val[0]);
|
|
152
|
-
}
|
|
153
|
-
for(let i = 1; i < length; i++) {
|
|
154
|
-
debug += ', ' + debugString(val[i]);
|
|
155
|
-
}
|
|
156
|
-
debug += ']';
|
|
157
|
-
return debug;
|
|
158
|
-
}
|
|
159
|
-
// Test for built-in
|
|
160
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
161
|
-
let className;
|
|
162
|
-
if (builtInMatches.length > 1) {
|
|
163
|
-
className = builtInMatches[1];
|
|
164
|
-
} else {
|
|
165
|
-
// Failed to match the standard '[object ClassName]'
|
|
166
|
-
return toString.call(val);
|
|
167
|
-
}
|
|
168
|
-
if (className == 'Object') {
|
|
169
|
-
// we're a user defined class or Object
|
|
170
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
171
|
-
// easier than looping through ownProperties of `val`.
|
|
172
|
-
try {
|
|
173
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
174
|
-
} catch (_) {
|
|
175
|
-
return 'Object';
|
|
176
|
-
}
|
|
121
|
+
let cachedUint32Memory0 = null;
|
|
122
|
+
|
|
123
|
+
function getUint32Memory0() {
|
|
124
|
+
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
125
|
+
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
177
126
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
127
|
+
return cachedUint32Memory0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
131
|
+
ptr = ptr >>> 0;
|
|
132
|
+
const mem = getUint32Memory0();
|
|
133
|
+
const slice = mem.subarray(ptr / 4, ptr / 4 + len);
|
|
134
|
+
const result = [];
|
|
135
|
+
for (let i = 0; i < slice.length; i++) {
|
|
136
|
+
result.push(takeObject(slice[i]));
|
|
181
137
|
}
|
|
182
|
-
|
|
183
|
-
return className;
|
|
138
|
+
return result;
|
|
184
139
|
}
|
|
185
140
|
|
|
186
141
|
let stack_pointer = 128;
|
|
@@ -191,6 +146,10 @@ function addBorrowedObject(obj) {
|
|
|
191
146
|
return stack_pointer;
|
|
192
147
|
}
|
|
193
148
|
/**
|
|
149
|
+
* Escapes all regular expression meta characters in `text`.
|
|
150
|
+
*
|
|
151
|
+
* The string returned may be safely used as a literal in a regular
|
|
152
|
+
* expression.
|
|
194
153
|
* @param {string} text
|
|
195
154
|
* @returns {string}
|
|
196
155
|
*/
|
|
@@ -238,7 +197,9 @@ class RRegex {
|
|
|
238
197
|
wasm.__wbg_rregex_free(ptr);
|
|
239
198
|
}
|
|
240
199
|
/**
|
|
241
|
-
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
200
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
201
|
+
* to search, split or replace text in a string.
|
|
202
|
+
*
|
|
242
203
|
* If an invalid expression is given, then an error is returned.
|
|
243
204
|
* @param {string} re
|
|
244
205
|
*/
|
|
@@ -261,11 +222,26 @@ class RRegex {
|
|
|
261
222
|
}
|
|
262
223
|
}
|
|
263
224
|
/**
|
|
264
|
-
* Returns true if and only if there is a match for the regex in the
|
|
265
|
-
*
|
|
225
|
+
* Returns true if and only if there is a match for the regex in the
|
|
226
|
+
* string given.
|
|
227
|
+
*
|
|
228
|
+
* It is recommended to use this method if all you need to do is test
|
|
229
|
+
* a match, since the underlying matching engine may be able to do less
|
|
230
|
+
* work.
|
|
231
|
+
*
|
|
232
|
+
* # Example
|
|
233
|
+
*
|
|
234
|
+
* Test if some text contains at least one word with exactly 13
|
|
235
|
+
* Unicode word characters:
|
|
236
|
+
*
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
239
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
266
242
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
267
|
-
* @param {string} text
|
|
268
|
-
* @
|
|
243
|
+
* @param {string} text - The string against which to match the regular expression
|
|
244
|
+
* @return {boolean}
|
|
269
245
|
*/
|
|
270
246
|
isMatch(text) {
|
|
271
247
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -275,11 +251,14 @@ class RRegex {
|
|
|
275
251
|
}
|
|
276
252
|
/**
|
|
277
253
|
* Returns the same as is_match, but starts the search at the given offset.
|
|
278
|
-
* The significance of the starting point is that it takes the surrounding
|
|
254
|
+
* The significance of the starting point is that it takes the surrounding
|
|
255
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
256
|
+
* when `start == 0`.
|
|
257
|
+
*
|
|
279
258
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
280
|
-
* @param {string} text
|
|
281
|
-
* @param {number} start
|
|
282
|
-
* @
|
|
259
|
+
* @param {string} text - The string against which to match the regular expression
|
|
260
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
261
|
+
* @return {boolean}
|
|
283
262
|
*/
|
|
284
263
|
isMatchAt(text, start) {
|
|
285
264
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -288,51 +267,337 @@ class RRegex {
|
|
|
288
267
|
return ret !== 0;
|
|
289
268
|
}
|
|
290
269
|
/**
|
|
291
|
-
* Returns the start and end byte range of the leftmost-first match in
|
|
292
|
-
*
|
|
270
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
271
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
272
|
+
*
|
|
273
|
+
* Note that this should only be used if you want to discover the position
|
|
274
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
275
|
+
* `isMatch`.
|
|
276
|
+
*
|
|
277
|
+
* # Example
|
|
278
|
+
*
|
|
279
|
+
* Find the start and end location of the first word with exactly 13
|
|
280
|
+
* Unicode word characters:
|
|
281
|
+
*
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
284
|
+
* const m = new Regex("\\b\\w{13}\\b").find(text)
|
|
285
|
+
* expect(m.start).toBe(2)
|
|
286
|
+
* expect(m.end).toBe(15)
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
293
289
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
294
|
-
* @param {string} text
|
|
295
|
-
* @
|
|
290
|
+
* @param {string} text - The string against which to match the regular expression
|
|
291
|
+
* @return {Match}
|
|
296
292
|
*/
|
|
297
293
|
find(text) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
294
|
+
try {
|
|
295
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
296
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
297
|
+
const len0 = WASM_VECTOR_LEN;
|
|
298
|
+
wasm.rregex_find(retptr, this.__wbg_ptr, ptr0, len0);
|
|
299
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
300
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
301
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
302
|
+
if (r2) {
|
|
303
|
+
throw takeObject(r1);
|
|
304
|
+
}
|
|
305
|
+
return takeObject(r0);
|
|
306
|
+
} finally {
|
|
307
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
308
|
+
}
|
|
302
309
|
}
|
|
303
310
|
/**
|
|
304
|
-
* Returns the same as find, but starts the search at the given
|
|
305
|
-
*
|
|
311
|
+
* Returns the same as find, but starts the search at the given
|
|
312
|
+
* offset.
|
|
313
|
+
*
|
|
314
|
+
* The significance of the starting point is that it takes the surrounding
|
|
315
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
316
|
+
* match when `start == 0`.
|
|
317
|
+
*
|
|
306
318
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
307
|
-
* @param {string} text
|
|
308
|
-
* @param {number} start
|
|
309
|
-
* @returns {
|
|
319
|
+
* @param {string} text - The string against which to match the regular expression
|
|
320
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
321
|
+
* @returns {Match}
|
|
310
322
|
*/
|
|
311
323
|
findAt(text, start) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
324
|
+
try {
|
|
325
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
326
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
327
|
+
const len0 = WASM_VECTOR_LEN;
|
|
328
|
+
wasm.rregex_findAt(retptr, this.__wbg_ptr, ptr0, len0, start);
|
|
329
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
330
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
331
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
332
|
+
if (r2) {
|
|
333
|
+
throw takeObject(r1);
|
|
334
|
+
}
|
|
335
|
+
return takeObject(r0);
|
|
336
|
+
} finally {
|
|
337
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
338
|
+
}
|
|
316
339
|
}
|
|
317
340
|
/**
|
|
318
|
-
* Returns an array for each successive non-overlapping match in text
|
|
341
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
342
|
+
* returning the start and end byte indices with respect to `text`.
|
|
343
|
+
*
|
|
344
|
+
* # Example
|
|
345
|
+
*
|
|
346
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
347
|
+
* word characters:
|
|
348
|
+
*
|
|
349
|
+
* ```typescript
|
|
350
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
351
|
+
* const matches = new Regex("\\b\\w{13}\\b").findAll(text)
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
319
354
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
320
|
-
* @param {string} text
|
|
321
|
-
* @returns {
|
|
355
|
+
* @param {string} text - The string against which to match the regular expression
|
|
356
|
+
* @returns {Match}
|
|
322
357
|
*/
|
|
323
358
|
findAll(text) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
359
|
+
try {
|
|
360
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
361
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
362
|
+
const len0 = WASM_VECTOR_LEN;
|
|
363
|
+
wasm.rregex_findAll(retptr, this.__wbg_ptr, ptr0, len0);
|
|
364
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
365
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
366
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
367
|
+
if (r2) {
|
|
368
|
+
throw takeObject(r1);
|
|
369
|
+
}
|
|
370
|
+
return takeObject(r0);
|
|
371
|
+
} finally {
|
|
372
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Returns a list of the capture names in this regex.
|
|
377
|
+
*
|
|
378
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
379
|
+
*/
|
|
380
|
+
captureNames() {
|
|
381
|
+
try {
|
|
382
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
383
|
+
wasm.rregex_captureNames(retptr, this.__wbg_ptr);
|
|
384
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
385
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
386
|
+
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
387
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
388
|
+
return v1;
|
|
389
|
+
} finally {
|
|
390
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
395
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
396
|
+
* match. If no match is found, then `undefined` is returned.
|
|
397
|
+
*
|
|
398
|
+
* You should only use `captures` if you need access to the location of
|
|
399
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
400
|
+
* the location of the overall match.
|
|
401
|
+
*
|
|
402
|
+
* # Examples
|
|
403
|
+
*
|
|
404
|
+
* Say you have some text with movie names and their release years,
|
|
405
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
406
|
+
* looking like that, while also extracting the movie name and its release
|
|
407
|
+
* year separately.
|
|
408
|
+
*
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const re = new Regex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
411
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
412
|
+
* const caps = re.captures(text)
|
|
413
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
414
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
415
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
419
|
+
* capture group is indexed by the order of its opening `(`.
|
|
420
|
+
*
|
|
421
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
422
|
+
*
|
|
423
|
+
* ```typescript
|
|
424
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
425
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
426
|
+
* const caps = re.captures(text)
|
|
427
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
428
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
429
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
433
|
+
* @param {string} text - The string against which to match the regular expression
|
|
434
|
+
* @returns {Captures|undefined}
|
|
435
|
+
*/
|
|
436
|
+
captures(text) {
|
|
437
|
+
try {
|
|
438
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
439
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
440
|
+
const len0 = WASM_VECTOR_LEN;
|
|
441
|
+
wasm.rregex_captures(retptr, this.__wbg_ptr, ptr0, len0);
|
|
442
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
443
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
444
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
445
|
+
if (r2) {
|
|
446
|
+
throw takeObject(r1);
|
|
447
|
+
}
|
|
448
|
+
return takeObject(r0);
|
|
449
|
+
} finally {
|
|
450
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
455
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
456
|
+
* returns information about capturing group matches.
|
|
457
|
+
*
|
|
458
|
+
* # Example
|
|
459
|
+
*
|
|
460
|
+
* We can use this to find all movie titles and their release years in
|
|
461
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
462
|
+
*
|
|
463
|
+
* ```typescript
|
|
464
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
465
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
466
|
+
* for caps of re.captures_iter(text) {
|
|
467
|
+
* console.log(
|
|
468
|
+
* "Movie:", caps.name["title"].value, ","
|
|
469
|
+
* "Released:", caps.name["year"].value
|
|
470
|
+
* );
|
|
471
|
+
* }
|
|
472
|
+
* // Output:
|
|
473
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
474
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
475
|
+
* // Movie: M, Released: 1931
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
479
|
+
* @param {string} text - The string against which to match the regular expression
|
|
480
|
+
* @returns {Captures[]}
|
|
481
|
+
*/
|
|
482
|
+
capturesAll(text) {
|
|
483
|
+
try {
|
|
484
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
485
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
486
|
+
const len0 = WASM_VECTOR_LEN;
|
|
487
|
+
wasm.rregex_capturesAll(retptr, this.__wbg_ptr, ptr0, len0);
|
|
488
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
489
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
490
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
491
|
+
if (r2) {
|
|
492
|
+
throw takeObject(r1);
|
|
493
|
+
}
|
|
494
|
+
return takeObject(r0);
|
|
495
|
+
} finally {
|
|
496
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Returns the number of captures.
|
|
501
|
+
*
|
|
502
|
+
* This includes all named and unnamed groups, including the implicit
|
|
503
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
504
|
+
*
|
|
505
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
506
|
+
* length returned is guaranteed to be greater than zero.
|
|
507
|
+
*
|
|
508
|
+
* ## Example
|
|
509
|
+
*
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
512
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
513
|
+
*
|
|
514
|
+
* const re2 = new RRegex("foo")
|
|
515
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
516
|
+
*
|
|
517
|
+
* const re3 = new RRegex("(foo)")
|
|
518
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
519
|
+
*
|
|
520
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
521
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
522
|
+
*
|
|
523
|
+
* const re5 = new RRegex("[a&&b]")
|
|
524
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
528
|
+
* @returns {number}
|
|
529
|
+
*/
|
|
530
|
+
capturesLength() {
|
|
531
|
+
const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
|
|
532
|
+
return ret >>> 0;
|
|
328
533
|
}
|
|
329
534
|
/**
|
|
330
535
|
* Replaces the leftmost-first match with the replacement provided.
|
|
331
|
-
* The replacement can be a regular string (where `$N` and `$name` are
|
|
536
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
537
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
538
|
+
* `Captures` and returns the replaced string.
|
|
539
|
+
*
|
|
332
540
|
* If no match is found, then a copy of the string is returned unchanged.
|
|
541
|
+
*
|
|
542
|
+
* # Replacement string syntax
|
|
543
|
+
*
|
|
544
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
545
|
+
* corresponding capture group `name`.
|
|
546
|
+
*
|
|
547
|
+
* `name` may be an integer corresponding to the index of the
|
|
548
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
549
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
550
|
+
* underscores) corresponding to a named capture group.
|
|
551
|
+
*
|
|
552
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
553
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
554
|
+
*
|
|
555
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
556
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
557
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
558
|
+
*
|
|
559
|
+
* To write a literal `$` use `$$`.
|
|
560
|
+
*
|
|
561
|
+
* # Examples
|
|
562
|
+
*
|
|
563
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
564
|
+
* In typical usage, this can just be a normal string:
|
|
565
|
+
*
|
|
566
|
+
* ```typescript
|
|
567
|
+
* const re = new Regex("[^01]+")
|
|
568
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* Here's the example using this expansion technique with named capture
|
|
572
|
+
* groups:
|
|
573
|
+
*
|
|
574
|
+
* ```typescript
|
|
575
|
+
* const re = new Regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
576
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
577
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
581
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
582
|
+
*
|
|
583
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
584
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
585
|
+
* For example, if we wanted to join two words together with an
|
|
586
|
+
* underscore:
|
|
587
|
+
*
|
|
588
|
+
* ```typescript
|
|
589
|
+
* const re = new Regex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
590
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
591
|
+
* expect(result).toBe("deep_fried")
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
595
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
596
|
+
* string.
|
|
597
|
+
*
|
|
333
598
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
334
|
-
* @param {string} text
|
|
335
|
-
* @param {string} rep
|
|
599
|
+
* @param {string} text - The string against which to match the regular expression
|
|
600
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
336
601
|
* @returns {string}
|
|
337
602
|
*/
|
|
338
603
|
replace(text, rep) {
|
|
@@ -356,12 +621,17 @@ class RRegex {
|
|
|
356
621
|
}
|
|
357
622
|
}
|
|
358
623
|
/**
|
|
359
|
-
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
360
|
-
*
|
|
624
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
625
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
626
|
+
* are replaced.
|
|
627
|
+
*
|
|
628
|
+
* See the documentation for `replace` for details on how to access
|
|
629
|
+
* capturing group matches in the replacement string.
|
|
630
|
+
*
|
|
361
631
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
362
|
-
* @param {string} text
|
|
363
|
-
* @param {number} limit
|
|
364
|
-
* @param {string} rep
|
|
632
|
+
* @param {string} text - The string against which to match the regular expression
|
|
633
|
+
* @param {number} limit - Max number of replacement
|
|
634
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
365
635
|
* @returns {string}
|
|
366
636
|
*/
|
|
367
637
|
replacen(text, limit, rep) {
|
|
@@ -385,11 +655,17 @@ class RRegex {
|
|
|
385
655
|
}
|
|
386
656
|
}
|
|
387
657
|
/**
|
|
388
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
658
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
659
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
660
|
+
* `0`.
|
|
661
|
+
*
|
|
662
|
+
* See the documentation for `replace` for details on how to access
|
|
663
|
+
* capturing group matches in the replacement string.
|
|
664
|
+
*
|
|
389
665
|
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
390
666
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
391
|
-
* @param {string} text
|
|
392
|
-
* @param {string} rep
|
|
667
|
+
* @param {string} text - The string against which to match the regular expression
|
|
668
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
393
669
|
* @returns {string}
|
|
394
670
|
*/
|
|
395
671
|
replaceAll(text, rep) {
|
|
@@ -413,38 +689,109 @@ class RRegex {
|
|
|
413
689
|
}
|
|
414
690
|
}
|
|
415
691
|
/**
|
|
416
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
417
|
-
*
|
|
692
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
693
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
694
|
+
* text that *isn't* matched by the regular expression.
|
|
695
|
+
*
|
|
696
|
+
* This method will *not* copy the text given.
|
|
697
|
+
*
|
|
698
|
+
* # Example
|
|
699
|
+
*
|
|
700
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
701
|
+
*
|
|
702
|
+
* ```typescript
|
|
703
|
+
* const re = new Regex(r"[ \\t]+")
|
|
704
|
+
* const fields = re.split("a b \t c\td e")
|
|
705
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
706
|
+
* ```
|
|
707
|
+
*
|
|
418
708
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
419
|
-
* @param {string} text
|
|
420
|
-
* @returns {
|
|
709
|
+
* @param {string} text - The string against which to match the regular expression
|
|
710
|
+
* @returns {string[]}
|
|
421
711
|
*/
|
|
422
712
|
split(text) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
713
|
+
try {
|
|
714
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
715
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
716
|
+
const len0 = WASM_VECTOR_LEN;
|
|
717
|
+
wasm.rregex_split(retptr, this.__wbg_ptr, ptr0, len0);
|
|
718
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
719
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
720
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
721
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
722
|
+
return v2;
|
|
723
|
+
} finally {
|
|
724
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
725
|
+
}
|
|
427
726
|
}
|
|
428
727
|
/**
|
|
429
|
-
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
430
|
-
*
|
|
728
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
729
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
730
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
731
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
732
|
+
* string that is not split will be the last element in the iterator.
|
|
733
|
+
*
|
|
734
|
+
* This method will *not* copy the text given.
|
|
735
|
+
*
|
|
736
|
+
* # Example
|
|
737
|
+
*
|
|
738
|
+
* Get the first two words in some text:
|
|
739
|
+
*
|
|
740
|
+
* ```typescript
|
|
741
|
+
* const re = new Regex(r"\\W+")
|
|
742
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
743
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
744
|
+
* ```
|
|
431
745
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
432
|
-
* @param {string} text
|
|
433
|
-
* @param {number} limit
|
|
434
|
-
* @returns {
|
|
746
|
+
* @param {string} text - The string against which to match the regular expression
|
|
747
|
+
* @param {number} limit - Max number result elements
|
|
748
|
+
* @returns {string[]}
|
|
435
749
|
*/
|
|
436
750
|
splitn(text, limit) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
751
|
+
try {
|
|
752
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
753
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
754
|
+
const len0 = WASM_VECTOR_LEN;
|
|
755
|
+
wasm.rregex_splitn(retptr, this.__wbg_ptr, ptr0, len0, limit);
|
|
756
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
757
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
758
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
759
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
760
|
+
return v2;
|
|
761
|
+
} finally {
|
|
762
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
763
|
+
}
|
|
441
764
|
}
|
|
442
765
|
/**
|
|
443
766
|
* Returns the end location of a match in the text given.
|
|
444
|
-
*
|
|
767
|
+
*
|
|
768
|
+
* This method may have the same performance characteristics as
|
|
769
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
770
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
771
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
772
|
+
*
|
|
773
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
774
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
775
|
+
* it returns the offset at the point at which the internal regex engine
|
|
776
|
+
* has determined that a match has occurred. This may vary depending on
|
|
777
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
778
|
+
* change.
|
|
779
|
+
*
|
|
780
|
+
* # Example
|
|
781
|
+
*
|
|
782
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
783
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
784
|
+
* `a`.
|
|
785
|
+
*
|
|
786
|
+
* ```typescript
|
|
787
|
+
* const text = "aaaaa"
|
|
788
|
+
* const = new Regex("a+").shortest_match(text)
|
|
789
|
+
* expect(pos).toBe(1)
|
|
790
|
+
* ```
|
|
791
|
+
*
|
|
445
792
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
446
|
-
* @param {string} text
|
|
447
|
-
* @returns {number
|
|
793
|
+
* @param {string} text - The string against which to match the regular expression
|
|
794
|
+
* @returns {number|undefined}
|
|
448
795
|
*/
|
|
449
796
|
shortestMatch(text) {
|
|
450
797
|
try {
|
|
@@ -460,19 +807,23 @@ class RRegex {
|
|
|
460
807
|
}
|
|
461
808
|
}
|
|
462
809
|
/**
|
|
463
|
-
* Returns the same as shortest_match
|
|
464
|
-
*
|
|
810
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
811
|
+
* given offset.
|
|
812
|
+
*
|
|
813
|
+
* The significance of the starting point is that it takes the surrounding
|
|
814
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
815
|
+
* when `start == 0`.
|
|
465
816
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
466
|
-
* @param {string} text
|
|
467
|
-
* @param {number}
|
|
468
|
-
* @returns {number
|
|
817
|
+
* @param {string} text - The string against which to match the regular expression
|
|
818
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
819
|
+
* @returns {number|undefined}
|
|
469
820
|
*/
|
|
470
|
-
shortestMatchAt(text,
|
|
821
|
+
shortestMatchAt(text, start) {
|
|
471
822
|
try {
|
|
472
823
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
473
824
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
474
825
|
const len0 = WASM_VECTOR_LEN;
|
|
475
|
-
wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0,
|
|
826
|
+
wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0, start);
|
|
476
827
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
477
828
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
478
829
|
return r0 === 0 ? undefined : r1 >>> 0;
|
|
@@ -481,12 +832,24 @@ class RRegex {
|
|
|
481
832
|
}
|
|
482
833
|
}
|
|
483
834
|
/**
|
|
484
|
-
*
|
|
835
|
+
* Returns the regular expression into a high level intermediate
|
|
836
|
+
* representation.
|
|
485
837
|
* @returns {any}
|
|
486
838
|
*/
|
|
487
839
|
syntax() {
|
|
488
|
-
|
|
489
|
-
|
|
840
|
+
try {
|
|
841
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
842
|
+
wasm.rregex_syntax(retptr, this.__wbg_ptr);
|
|
843
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
844
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
845
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
846
|
+
if (r2) {
|
|
847
|
+
throw takeObject(r1);
|
|
848
|
+
}
|
|
849
|
+
return takeObject(r0);
|
|
850
|
+
} finally {
|
|
851
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
852
|
+
}
|
|
490
853
|
}
|
|
491
854
|
/**
|
|
492
855
|
* Returns a string representing the regular expression
|
|
@@ -512,7 +875,14 @@ class RRegex {
|
|
|
512
875
|
module.exports.RRegex = RRegex;
|
|
513
876
|
/**
|
|
514
877
|
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
515
|
-
* A regex set corresponds to the union of two or more regular expressions.
|
|
878
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
879
|
+
*
|
|
880
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
881
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
882
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
883
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
884
|
+
* with many alternates, since only one alternate can match at a time.
|
|
885
|
+
*
|
|
516
886
|
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
517
887
|
*/
|
|
518
888
|
class RRegexSet {
|
|
@@ -530,6 +900,18 @@ class RRegexSet {
|
|
|
530
900
|
}
|
|
531
901
|
/**
|
|
532
902
|
* Create a new regex set with the given regular expressions.
|
|
903
|
+
*
|
|
904
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
905
|
+
* expressions, then an error is returned.
|
|
906
|
+
*
|
|
907
|
+
* # Example
|
|
908
|
+
*
|
|
909
|
+
* Create a new regex set from an iterator of strings:
|
|
910
|
+
*
|
|
911
|
+
* ```typescript
|
|
912
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
913
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
914
|
+
* ```
|
|
533
915
|
* @param {Array<any>} list
|
|
534
916
|
*/
|
|
535
917
|
constructor(list) {
|
|
@@ -550,11 +932,33 @@ class RRegexSet {
|
|
|
550
932
|
}
|
|
551
933
|
}
|
|
552
934
|
/**
|
|
553
|
-
* Returns true if and only if one of the regexes in this set matches
|
|
554
|
-
*
|
|
935
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
936
|
+
* the text given.
|
|
937
|
+
*
|
|
938
|
+
* This method should be preferred if you only need to test whether any
|
|
939
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
940
|
+
* regexes matched. This is because the underlying matching engine will
|
|
941
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
942
|
+
* find all matches.
|
|
943
|
+
*
|
|
944
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
945
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
946
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
947
|
+
* text.
|
|
948
|
+
*
|
|
949
|
+
* # Example
|
|
950
|
+
*
|
|
951
|
+
* Tests whether a set matches some text:
|
|
952
|
+
*
|
|
953
|
+
* ```typescript
|
|
954
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
955
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
956
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
957
|
+
* ```
|
|
958
|
+
*
|
|
555
959
|
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
556
|
-
* @param {string} text
|
|
557
|
-
* @
|
|
960
|
+
* @param {string} text - The string against which to match the regular expression
|
|
961
|
+
* @return {boolean}
|
|
558
962
|
*/
|
|
559
963
|
isMatch(text) {
|
|
560
964
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -564,20 +968,63 @@ class RRegexSet {
|
|
|
564
968
|
}
|
|
565
969
|
/**
|
|
566
970
|
* Returns the set of regular expressions that match in the given text.
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
971
|
+
*
|
|
972
|
+
* The set returned contains the index of each regular expression that
|
|
973
|
+
* matches in the given text. The index is in correspondence with the
|
|
974
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
975
|
+
*
|
|
976
|
+
* The set can also be used to iterate over the matched indices.
|
|
977
|
+
*
|
|
978
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
979
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
980
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
981
|
+
* text.
|
|
982
|
+
*
|
|
983
|
+
* # Example
|
|
984
|
+
*
|
|
985
|
+
* Tests which regular expressions match the given text:
|
|
986
|
+
*
|
|
987
|
+
* ```typescript
|
|
988
|
+
* const set = new RegexSet([
|
|
989
|
+
* "\\w+",
|
|
990
|
+
* "\\d+",
|
|
991
|
+
* "\\pL+",
|
|
992
|
+
* "foo",
|
|
993
|
+
* "bar",
|
|
994
|
+
* "barfoo",
|
|
995
|
+
* "foobar",
|
|
996
|
+
* ])
|
|
997
|
+
* const matches = set.matches("foobar")
|
|
998
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
999
|
+
* ```
|
|
1000
|
+
*
|
|
1001
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1002
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1003
|
+
* @return {number[]}
|
|
571
1004
|
*/
|
|
572
1005
|
matches(text) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
1006
|
+
try {
|
|
1007
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1008
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1009
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1010
|
+
wasm.rregexset_matches(retptr, this.__wbg_ptr, ptr0, len0);
|
|
1011
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
1012
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
1013
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
1014
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
1015
|
+
return v2;
|
|
1016
|
+
} finally {
|
|
1017
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1018
|
+
}
|
|
577
1019
|
}
|
|
578
1020
|
}
|
|
579
1021
|
module.exports.RRegexSet = RRegexSet;
|
|
580
1022
|
|
|
1023
|
+
module.exports.__wbindgen_number_new = function(arg0) {
|
|
1024
|
+
const ret = arg0;
|
|
1025
|
+
return addHeapObject(ret);
|
|
1026
|
+
};
|
|
1027
|
+
|
|
581
1028
|
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
582
1029
|
takeObject(arg0);
|
|
583
1030
|
};
|
|
@@ -587,16 +1034,6 @@ module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
|
587
1034
|
return addHeapObject(ret);
|
|
588
1035
|
};
|
|
589
1036
|
|
|
590
|
-
module.exports.__wbindgen_number_new = function(arg0) {
|
|
591
|
-
const ret = arg0;
|
|
592
|
-
return addHeapObject(ret);
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
module.exports.__wbindgen_is_string = function(arg0) {
|
|
596
|
-
const ret = typeof(getObject(arg0)) === 'string';
|
|
597
|
-
return ret;
|
|
598
|
-
};
|
|
599
|
-
|
|
600
1037
|
module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
601
1038
|
const obj = getObject(arg1);
|
|
602
1039
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
@@ -606,6 +1043,25 @@ module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
|
606
1043
|
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
607
1044
|
};
|
|
608
1045
|
|
|
1046
|
+
module.exports.__wbindgen_error_new = function(arg0, arg1) {
|
|
1047
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1048
|
+
return addHeapObject(ret);
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
module.exports.__wbindgen_object_clone_ref = function(arg0) {
|
|
1052
|
+
const ret = getObject(arg0);
|
|
1053
|
+
return addHeapObject(ret);
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
1057
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
1058
|
+
return addHeapObject(ret);
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
module.exports.__wbg_set_9182712abebf82ef = function(arg0, arg1, arg2) {
|
|
1062
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
1063
|
+
};
|
|
1064
|
+
|
|
609
1065
|
module.exports.__wbg_get_f01601b5a68d10e3 = function(arg0, arg1) {
|
|
610
1066
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
611
1067
|
return addHeapObject(ret);
|
|
@@ -626,13 +1082,37 @@ module.exports.__wbg_new_9fb8d994e1c0aaac = function() {
|
|
|
626
1082
|
return addHeapObject(ret);
|
|
627
1083
|
};
|
|
628
1084
|
|
|
1085
|
+
module.exports.__wbg_set_f2740edb12e318cd = function(arg0, arg1, arg2) {
|
|
1086
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
module.exports.__wbg_from_71add2e723d1f1b2 = function(arg0) {
|
|
1090
|
+
const ret = Array.from(getObject(arg0));
|
|
1091
|
+
return addHeapObject(ret);
|
|
1092
|
+
};
|
|
1093
|
+
|
|
629
1094
|
module.exports.__wbg_push_901f3914205d44de = function(arg0, arg1) {
|
|
630
1095
|
const ret = getObject(arg0).push(getObject(arg1));
|
|
631
1096
|
return ret;
|
|
632
1097
|
};
|
|
633
1098
|
|
|
634
|
-
module.exports.
|
|
635
|
-
const ret =
|
|
1099
|
+
module.exports.__wbg_fromCodePoint_fd9383eff8873c75 = function() { return handleError(function (arg0) {
|
|
1100
|
+
const ret = String.fromCodePoint(arg0 >>> 0);
|
|
1101
|
+
return addHeapObject(ret);
|
|
1102
|
+
}, arguments) };
|
|
1103
|
+
|
|
1104
|
+
module.exports.__wbg_buffer_a448f833075b71ba = function(arg0) {
|
|
1105
|
+
const ret = getObject(arg0).buffer;
|
|
1106
|
+
return addHeapObject(ret);
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
module.exports.__wbg_newwithbyteoffsetandlength_d0482f893617af71 = function(arg0, arg1, arg2) {
|
|
1110
|
+
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
1111
|
+
return addHeapObject(ret);
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
module.exports.__wbg_new_8f67e318f15d7254 = function(arg0) {
|
|
1115
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
636
1116
|
return addHeapObject(ret);
|
|
637
1117
|
};
|
|
638
1118
|
|
|
@@ -641,18 +1121,15 @@ module.exports.__wbg_set_759f75cd92b612d2 = function() { return handleError(func
|
|
|
641
1121
|
return ret;
|
|
642
1122
|
}, arguments) };
|
|
643
1123
|
|
|
644
|
-
module.exports.__wbindgen_debug_string = function(arg0, arg1) {
|
|
645
|
-
const ret = debugString(getObject(arg1));
|
|
646
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
647
|
-
const len1 = WASM_VECTOR_LEN;
|
|
648
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
649
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
650
|
-
};
|
|
651
|
-
|
|
652
1124
|
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
653
1125
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
654
1126
|
};
|
|
655
1127
|
|
|
1128
|
+
module.exports.__wbindgen_memory = function() {
|
|
1129
|
+
const ret = wasm.memory;
|
|
1130
|
+
return addHeapObject(ret);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
656
1133
|
const path = require('path').join(__dirname, 'rregex.wasm');
|
|
657
1134
|
const bytes = require('fs').readFileSync(path);
|
|
658
1135
|
|
|
@@ -668,8 +1145,8 @@ module.exports.metadata = {
|
|
|
668
1145
|
"authors": [
|
|
669
1146
|
"Fede Ramirez <i@2fd.me>"
|
|
670
1147
|
],
|
|
671
|
-
"homepage": "
|
|
1148
|
+
"homepage": "http://rregex.dev",
|
|
672
1149
|
"repository": "https://github.com/2fd/rregex",
|
|
673
|
-
"regex": "1.
|
|
674
|
-
"regex-syntax": "0.
|
|
1150
|
+
"regex": "1.9.6",
|
|
1151
|
+
"regex-syntax": "0.7.5"
|
|
675
1152
|
}
|