rregex 1.0.0 → 1.0.1
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 +190 -1
- package/babel.config.js +7 -0
- package/jest.transform.js +3 -0
- package/lib/browser.d.ts +461 -23
- package/lib/browser.js +289 -82
- package/lib/commonjs.d.ts +440 -10
- package/lib/commonjs.js +297 -85
- package/lib/module.d.ts +440 -10
- package/lib/module.js +295 -84
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +21 -13
- package/lib/types.d.ts +461 -23
- package/package.json +13 -3
- package/test/rregex.test.ts +232 -0
package/lib/browser.js
CHANGED
|
@@ -46,6 +46,73 @@ function addHeapObject(obj) {
|
|
|
46
46
|
return idx;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
let WASM_VECTOR_LEN = 0;
|
|
50
|
+
|
|
51
|
+
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
52
|
+
|
|
53
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
54
|
+
? function (arg, view) {
|
|
55
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
56
|
+
}
|
|
57
|
+
: function (arg, view) {
|
|
58
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
59
|
+
view.set(buf);
|
|
60
|
+
return {
|
|
61
|
+
read: arg.length,
|
|
62
|
+
written: buf.length
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
67
|
+
|
|
68
|
+
if (realloc === undefined) {
|
|
69
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
70
|
+
const ptr = malloc(buf.length);
|
|
71
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
72
|
+
WASM_VECTOR_LEN = buf.length;
|
|
73
|
+
return ptr;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let len = arg.length;
|
|
77
|
+
let ptr = malloc(len);
|
|
78
|
+
|
|
79
|
+
const mem = getUint8Memory0();
|
|
80
|
+
|
|
81
|
+
let offset = 0;
|
|
82
|
+
|
|
83
|
+
for (; offset < len; offset++) {
|
|
84
|
+
const code = arg.charCodeAt(offset);
|
|
85
|
+
if (code > 0x7F) break;
|
|
86
|
+
mem[ptr + offset] = code;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (offset !== len) {
|
|
90
|
+
if (offset !== 0) {
|
|
91
|
+
arg = arg.slice(offset);
|
|
92
|
+
}
|
|
93
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
94
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
95
|
+
const ret = encodeString(arg, view);
|
|
96
|
+
|
|
97
|
+
offset += ret.written;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
WASM_VECTOR_LEN = offset;
|
|
101
|
+
return ptr;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isLikeNone(x) {
|
|
105
|
+
return x === undefined || x === null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let cachegetInt32Memory0 = null;
|
|
109
|
+
function getInt32Memory0() {
|
|
110
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
111
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
112
|
+
}
|
|
113
|
+
return cachegetInt32Memory0;
|
|
114
|
+
}
|
|
115
|
+
|
|
49
116
|
function debugString(val) {
|
|
50
117
|
// primitive types
|
|
51
118
|
const type = typeof val;
|
|
@@ -110,69 +177,25 @@ function debugString(val) {
|
|
|
110
177
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
111
178
|
return className;
|
|
112
179
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
132
|
-
|
|
133
|
-
if (realloc === undefined) {
|
|
134
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
135
|
-
const ptr = malloc(buf.length);
|
|
136
|
-
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
137
|
-
WASM_VECTOR_LEN = buf.length;
|
|
138
|
-
return ptr;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let len = arg.length;
|
|
142
|
-
let ptr = malloc(len);
|
|
143
|
-
|
|
144
|
-
const mem = getUint8Memory0();
|
|
145
|
-
|
|
146
|
-
let offset = 0;
|
|
147
|
-
|
|
148
|
-
for (; offset < len; offset++) {
|
|
149
|
-
const code = arg.charCodeAt(offset);
|
|
150
|
-
if (code > 0x7F) break;
|
|
151
|
-
mem[ptr + offset] = code;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (offset !== len) {
|
|
155
|
-
if (offset !== 0) {
|
|
156
|
-
arg = arg.slice(offset);
|
|
157
|
-
}
|
|
158
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
159
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
160
|
-
const ret = encodeString(arg, view);
|
|
161
|
-
|
|
162
|
-
offset += ret.written;
|
|
180
|
+
/**
|
|
181
|
+
* @param {string} text
|
|
182
|
+
* @returns {string}
|
|
183
|
+
*/
|
|
184
|
+
export function escape(text) {
|
|
185
|
+
try {
|
|
186
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
187
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
188
|
+
var len0 = WASM_VECTOR_LEN;
|
|
189
|
+
wasm.escape(retptr, ptr0, len0);
|
|
190
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
191
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
192
|
+
return getStringFromWasm0(r0, r1);
|
|
193
|
+
} finally {
|
|
194
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
195
|
+
wasm.__wbindgen_free(r0, r1);
|
|
163
196
|
}
|
|
164
|
-
|
|
165
|
-
WASM_VECTOR_LEN = offset;
|
|
166
|
-
return ptr;
|
|
167
197
|
}
|
|
168
198
|
|
|
169
|
-
let cachegetInt32Memory0 = null;
|
|
170
|
-
function getInt32Memory0() {
|
|
171
|
-
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
172
|
-
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
173
|
-
}
|
|
174
|
-
return cachegetInt32Memory0;
|
|
175
|
-
}
|
|
176
199
|
/**
|
|
177
200
|
* @returns {any}
|
|
178
201
|
*/
|
|
@@ -181,6 +204,14 @@ export function get_metadata() {
|
|
|
181
204
|
return takeObject(ret);
|
|
182
205
|
}
|
|
183
206
|
|
|
207
|
+
let stack_pointer = 32;
|
|
208
|
+
|
|
209
|
+
function addBorrowedObject(obj) {
|
|
210
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
211
|
+
heap[--stack_pointer] = obj;
|
|
212
|
+
return stack_pointer;
|
|
213
|
+
}
|
|
214
|
+
|
|
184
215
|
function handleError(f, args) {
|
|
185
216
|
try {
|
|
186
217
|
return f.apply(this, args);
|
|
@@ -189,11 +220,13 @@ function handleError(f, args) {
|
|
|
189
220
|
}
|
|
190
221
|
}
|
|
191
222
|
/**
|
|
223
|
+
* A compiled regular expression for matching Unicode strings.
|
|
224
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
192
225
|
*/
|
|
193
|
-
export class
|
|
226
|
+
export class RRegex {
|
|
194
227
|
|
|
195
228
|
static __wrap(ptr) {
|
|
196
|
-
const obj = Object.create(
|
|
229
|
+
const obj = Object.create(RRegex.prototype);
|
|
197
230
|
obj.ptr = ptr;
|
|
198
231
|
|
|
199
232
|
return obj;
|
|
@@ -208,70 +241,90 @@ export class RRegExp {
|
|
|
208
241
|
|
|
209
242
|
free() {
|
|
210
243
|
const ptr = this.__destroy_into_raw();
|
|
211
|
-
wasm.
|
|
244
|
+
wasm.__wbg_rregex_free(ptr);
|
|
212
245
|
}
|
|
213
246
|
/**
|
|
247
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
248
|
+
* If an invalid expression is given, then an error is returned.
|
|
214
249
|
* @param {string} re
|
|
215
250
|
*/
|
|
216
251
|
constructor(re) {
|
|
217
252
|
var ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
218
253
|
var len0 = WASM_VECTOR_LEN;
|
|
219
|
-
var ret = wasm.
|
|
220
|
-
return
|
|
254
|
+
var ret = wasm.rregex_new(ptr0, len0);
|
|
255
|
+
return RRegex.__wrap(ret);
|
|
221
256
|
}
|
|
222
257
|
/**
|
|
258
|
+
* Returns true if and only if there is a match for the regex in the string given.
|
|
259
|
+
* It is recommended to use this method if all you need to do is test a match, since the underlying matching engine may be able to do less work.
|
|
260
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
223
261
|
* @param {string} text
|
|
224
262
|
* @returns {boolean}
|
|
225
263
|
*/
|
|
226
|
-
|
|
264
|
+
isMatch(text) {
|
|
227
265
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
228
266
|
var len0 = WASM_VECTOR_LEN;
|
|
229
|
-
var ret = wasm.
|
|
267
|
+
var ret = wasm.rregex_isMatch(this.ptr, ptr0, len0);
|
|
230
268
|
return ret !== 0;
|
|
231
269
|
}
|
|
232
270
|
/**
|
|
271
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
272
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the `\A` anchor can only match when `start == 0`.
|
|
273
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
233
274
|
* @param {string} text
|
|
234
275
|
* @param {number} start
|
|
235
276
|
* @returns {boolean}
|
|
236
277
|
*/
|
|
237
|
-
|
|
278
|
+
isMatchAt(text, start) {
|
|
238
279
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
239
280
|
var len0 = WASM_VECTOR_LEN;
|
|
240
|
-
var ret = wasm.
|
|
281
|
+
var ret = wasm.rregex_isMatchAt(this.ptr, ptr0, len0, start);
|
|
241
282
|
return ret !== 0;
|
|
242
283
|
}
|
|
243
284
|
/**
|
|
285
|
+
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
286
|
+
* Note that this should only be used if you want to discover the position of the match. Testing the existence of a match is faster if you use `is_match`.
|
|
287
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
244
288
|
* @param {string} text
|
|
245
289
|
* @returns {any}
|
|
246
290
|
*/
|
|
247
291
|
find(text) {
|
|
248
292
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
249
293
|
var len0 = WASM_VECTOR_LEN;
|
|
250
|
-
var ret = wasm.
|
|
294
|
+
var ret = wasm.rregex_find(this.ptr, ptr0, len0);
|
|
251
295
|
return takeObject(ret);
|
|
252
296
|
}
|
|
253
297
|
/**
|
|
298
|
+
* Returns the same as find, but starts the search at the given offset.
|
|
299
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
300
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
254
301
|
* @param {string} text
|
|
255
302
|
* @param {number} start
|
|
256
303
|
* @returns {any}
|
|
257
304
|
*/
|
|
258
|
-
|
|
305
|
+
findAt(text, start) {
|
|
259
306
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
260
307
|
var len0 = WASM_VECTOR_LEN;
|
|
261
|
-
var ret = wasm.
|
|
308
|
+
var ret = wasm.rregex_findAt(this.ptr, ptr0, len0, start);
|
|
262
309
|
return takeObject(ret);
|
|
263
310
|
}
|
|
264
311
|
/**
|
|
312
|
+
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
313
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
265
314
|
* @param {string} text
|
|
266
315
|
* @returns {any}
|
|
267
316
|
*/
|
|
268
|
-
|
|
317
|
+
findAll(text) {
|
|
269
318
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
270
319
|
var len0 = WASM_VECTOR_LEN;
|
|
271
|
-
var ret = wasm.
|
|
320
|
+
var ret = wasm.rregex_findAll(this.ptr, ptr0, len0);
|
|
272
321
|
return takeObject(ret);
|
|
273
322
|
}
|
|
274
323
|
/**
|
|
324
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
325
|
+
* The replacement can be a regular string (where `$N` and `$name` are expanded to match capture groups) or a function that takes the matches’ `Captures` and returns the replaced string.
|
|
326
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
327
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
275
328
|
* @param {string} text
|
|
276
329
|
* @param {string} rep
|
|
277
330
|
* @returns {string}
|
|
@@ -283,7 +336,7 @@ export class RRegExp {
|
|
|
283
336
|
var len0 = WASM_VECTOR_LEN;
|
|
284
337
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
285
338
|
var len1 = WASM_VECTOR_LEN;
|
|
286
|
-
wasm.
|
|
339
|
+
wasm.rregex_replace(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
287
340
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
288
341
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
289
342
|
return getStringFromWasm0(r0, r1);
|
|
@@ -293,6 +346,9 @@ export class RRegExp {
|
|
|
293
346
|
}
|
|
294
347
|
}
|
|
295
348
|
/**
|
|
349
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
350
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
351
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
296
352
|
* @param {string} text
|
|
297
353
|
* @param {number} limit
|
|
298
354
|
* @param {string} rep
|
|
@@ -305,7 +361,7 @@ export class RRegExp {
|
|
|
305
361
|
var len0 = WASM_VECTOR_LEN;
|
|
306
362
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
307
363
|
var len1 = WASM_VECTOR_LEN;
|
|
308
|
-
wasm.
|
|
364
|
+
wasm.rregex_replacen(retptr, this.ptr, ptr0, len0, limit, ptr1, len1);
|
|
309
365
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
310
366
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
311
367
|
return getStringFromWasm0(r0, r1);
|
|
@@ -315,18 +371,21 @@ export class RRegExp {
|
|
|
315
371
|
}
|
|
316
372
|
}
|
|
317
373
|
/**
|
|
374
|
+
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
375
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
376
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
318
377
|
* @param {string} text
|
|
319
378
|
* @param {string} rep
|
|
320
379
|
* @returns {string}
|
|
321
380
|
*/
|
|
322
|
-
|
|
381
|
+
replaceAll(text, rep) {
|
|
323
382
|
try {
|
|
324
383
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
325
384
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
326
385
|
var len0 = WASM_VECTOR_LEN;
|
|
327
386
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
328
387
|
var len1 = WASM_VECTOR_LEN;
|
|
329
|
-
wasm.
|
|
388
|
+
wasm.rregex_replaceAll(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
330
389
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
331
390
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
332
391
|
return getStringFromWasm0(r0, r1);
|
|
@@ -336,16 +395,22 @@ export class RRegExp {
|
|
|
336
395
|
}
|
|
337
396
|
}
|
|
338
397
|
/**
|
|
398
|
+
* Returns an iterator of substrings of `text` delimited by a match of the regular expression. Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression.
|
|
399
|
+
* This method will not copy the text given.
|
|
400
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
339
401
|
* @param {string} text
|
|
340
402
|
* @returns {any}
|
|
341
403
|
*/
|
|
342
404
|
split(text) {
|
|
343
405
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
344
406
|
var len0 = WASM_VECTOR_LEN;
|
|
345
|
-
var ret = wasm.
|
|
407
|
+
var ret = wasm.rregex_split(this.ptr, ptr0, len0);
|
|
346
408
|
return takeObject(ret);
|
|
347
409
|
}
|
|
348
410
|
/**
|
|
411
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited by a match of the regular expression. (A limit of 0 will return no substrings.) Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression. The remainder of the string that is not split will be the last element in the iterator.
|
|
412
|
+
* This method will not copy the text given.
|
|
413
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
349
414
|
* @param {string} text
|
|
350
415
|
* @param {number} limit
|
|
351
416
|
* @returns {any}
|
|
@@ -353,14 +418,136 @@ export class RRegExp {
|
|
|
353
418
|
splitn(text, limit) {
|
|
354
419
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
355
420
|
var len0 = WASM_VECTOR_LEN;
|
|
356
|
-
var ret = wasm.
|
|
421
|
+
var ret = wasm.rregex_splitn(this.ptr, ptr0, len0, limit);
|
|
357
422
|
return takeObject(ret);
|
|
358
423
|
}
|
|
359
424
|
/**
|
|
425
|
+
* Returns the end location of a match in the text given.
|
|
426
|
+
* This method may have the same performance characteristics as `is_match`, except it provides an end location for a match. In particular, the location returned may be shorter than the proper end of the leftmost-first match.
|
|
427
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
428
|
+
* @param {string} text
|
|
429
|
+
* @returns {number | undefined}
|
|
430
|
+
*/
|
|
431
|
+
shortestMatch(text) {
|
|
432
|
+
try {
|
|
433
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
434
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
435
|
+
var len0 = WASM_VECTOR_LEN;
|
|
436
|
+
wasm.rregex_shortestMatch(retptr, this.ptr, ptr0, len0);
|
|
437
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
438
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
439
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
440
|
+
} finally {
|
|
441
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
446
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
447
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
448
|
+
* @param {string} text
|
|
449
|
+
* @param {number} limit
|
|
450
|
+
* @returns {number | undefined}
|
|
451
|
+
*/
|
|
452
|
+
shortestMatchAt(text, limit) {
|
|
453
|
+
try {
|
|
454
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
455
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
456
|
+
var len0 = WASM_VECTOR_LEN;
|
|
457
|
+
wasm.rregex_shortestMatchAt(retptr, this.ptr, ptr0, len0, limit);
|
|
458
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
459
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
460
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
461
|
+
} finally {
|
|
462
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Return the Regex syntax object
|
|
360
467
|
* @returns {any}
|
|
361
468
|
*/
|
|
362
469
|
syntax() {
|
|
363
|
-
var ret = wasm.
|
|
470
|
+
var ret = wasm.rregex_syntax(this.ptr);
|
|
471
|
+
return takeObject(ret);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Returns a string representing the regular expression
|
|
475
|
+
* @returns {string}
|
|
476
|
+
*/
|
|
477
|
+
toString() {
|
|
478
|
+
try {
|
|
479
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
480
|
+
wasm.rregex_toString(retptr, this.ptr);
|
|
481
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
482
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
483
|
+
return getStringFromWasm0(r0, r1);
|
|
484
|
+
} finally {
|
|
485
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
486
|
+
wasm.__wbindgen_free(r0, r1);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
492
|
+
* A regex set corresponds to the union of two or more regular expressions. That is, a regex set will match text where at least one of its constituent regular expressions matches. A regex set as its formulated here provides a touch more power: it will also report which regular expressions in the set match. Indeed, this is the key difference between regex sets and a single `Regex` with many alternates, since only one alternate can match at a time.
|
|
493
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
494
|
+
*/
|
|
495
|
+
export class RRegexSet {
|
|
496
|
+
|
|
497
|
+
static __wrap(ptr) {
|
|
498
|
+
const obj = Object.create(RRegexSet.prototype);
|
|
499
|
+
obj.ptr = ptr;
|
|
500
|
+
|
|
501
|
+
return obj;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
__destroy_into_raw() {
|
|
505
|
+
const ptr = this.ptr;
|
|
506
|
+
this.ptr = 0;
|
|
507
|
+
|
|
508
|
+
return ptr;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
free() {
|
|
512
|
+
const ptr = this.__destroy_into_raw();
|
|
513
|
+
wasm.__wbg_rregexset_free(ptr);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Create a new regex set with the given regular expressions.
|
|
517
|
+
* @param {Array<any>} list
|
|
518
|
+
*/
|
|
519
|
+
constructor(list) {
|
|
520
|
+
try {
|
|
521
|
+
var ret = wasm.rregexset_new(addBorrowedObject(list));
|
|
522
|
+
return RRegexSet.__wrap(ret);
|
|
523
|
+
} finally {
|
|
524
|
+
heap[stack_pointer++] = undefined;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
529
|
+
* This method should be preferred if you only need to test whether any of the regexes in the set should match, but don’t care about which regexes matched. This is because the underlying matching engine will quit immediately after seeing the first match instead of continuing to find all matches.
|
|
530
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
531
|
+
* @param {string} text
|
|
532
|
+
* @returns {boolean}
|
|
533
|
+
*/
|
|
534
|
+
isMatch(text) {
|
|
535
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
536
|
+
var len0 = WASM_VECTOR_LEN;
|
|
537
|
+
var ret = wasm.rregexset_isMatch(this.ptr, ptr0, len0);
|
|
538
|
+
return ret !== 0;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Returns the set of regular expressions that match in the given text.
|
|
542
|
+
* The set returned contains the index of each regular expression that matches in the given text. The index is in correspondence with the order of regular expressions given to RegexSet’s constructor.
|
|
543
|
+
* the set can also be used to iterate over the matched indices.
|
|
544
|
+
* @param {string} text
|
|
545
|
+
* @returns {any}
|
|
546
|
+
*/
|
|
547
|
+
matches(text) {
|
|
548
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
549
|
+
var len0 = WASM_VECTOR_LEN;
|
|
550
|
+
var ret = wasm.rregexset_matches(this.ptr, ptr0, len0);
|
|
364
551
|
return takeObject(ret);
|
|
365
552
|
}
|
|
366
553
|
}
|
|
@@ -398,7 +585,7 @@ async function load(module, imports) {
|
|
|
398
585
|
|
|
399
586
|
async function init(input) {
|
|
400
587
|
if (typeof input === 'undefined') {
|
|
401
|
-
input = new URL('
|
|
588
|
+
input = new URL('rregex.wasm', import.meta.url);
|
|
402
589
|
}
|
|
403
590
|
const imports = {};
|
|
404
591
|
imports.wbg = {};
|
|
@@ -413,6 +600,26 @@ async function init(input) {
|
|
|
413
600
|
var ret = arg0;
|
|
414
601
|
return addHeapObject(ret);
|
|
415
602
|
};
|
|
603
|
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
604
|
+
var ret = typeof(getObject(arg0)) === 'string';
|
|
605
|
+
return ret;
|
|
606
|
+
};
|
|
607
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
608
|
+
const obj = getObject(arg1);
|
|
609
|
+
var ret = typeof(obj) === 'string' ? obj : undefined;
|
|
610
|
+
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
611
|
+
var len0 = WASM_VECTOR_LEN;
|
|
612
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
613
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
614
|
+
};
|
|
615
|
+
imports.wbg.__wbg_get_67189fe0b323d288 = function(arg0, arg1) {
|
|
616
|
+
var ret = getObject(arg0)[arg1 >>> 0];
|
|
617
|
+
return addHeapObject(ret);
|
|
618
|
+
};
|
|
619
|
+
imports.wbg.__wbg_length_42e02f5a04d67464 = function(arg0) {
|
|
620
|
+
var ret = getObject(arg0).length;
|
|
621
|
+
return ret;
|
|
622
|
+
};
|
|
416
623
|
imports.wbg.__wbg_new_949bbc1147195c4e = function() {
|
|
417
624
|
var ret = new Array();
|
|
418
625
|
return addHeapObject(ret);
|