rregex 1.0.0 → 1.1.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 +230 -1
- package/babel.config.js +7 -0
- package/jest.transform.js +3 -0
- package/lib/browser.d.ts +471 -26
- package/lib/browser.js +299 -88
- package/lib/commonjs.d.ts +450 -12
- package/lib/commonjs.js +306 -90
- package/lib/module.d.ts +450 -12
- package/lib/module.js +293 -90
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +21 -14
- package/lib/types.d.ts +471 -26
- package/package.json +14 -3
- package/test/rregex.test.ts +235 -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,75 +177,31 @@ 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
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* @returns {any}
|
|
178
|
-
*/
|
|
179
|
-
export function get_metadata() {
|
|
180
|
-
var ret = wasm.get_metadata();
|
|
181
|
-
return takeObject(ret);
|
|
199
|
+
let stack_pointer = 32;
|
|
200
|
+
|
|
201
|
+
function addBorrowedObject(obj) {
|
|
202
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
203
|
+
heap[--stack_pointer] = obj;
|
|
204
|
+
return stack_pointer;
|
|
182
205
|
}
|
|
183
206
|
|
|
184
207
|
function handleError(f, args) {
|
|
@@ -189,11 +212,13 @@ function handleError(f, args) {
|
|
|
189
212
|
}
|
|
190
213
|
}
|
|
191
214
|
/**
|
|
215
|
+
* A compiled regular expression for matching Unicode strings.
|
|
216
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
192
217
|
*/
|
|
193
|
-
export class
|
|
218
|
+
export class RRegex {
|
|
194
219
|
|
|
195
220
|
static __wrap(ptr) {
|
|
196
|
-
const obj = Object.create(
|
|
221
|
+
const obj = Object.create(RRegex.prototype);
|
|
197
222
|
obj.ptr = ptr;
|
|
198
223
|
|
|
199
224
|
return obj;
|
|
@@ -208,70 +233,90 @@ export class RRegExp {
|
|
|
208
233
|
|
|
209
234
|
free() {
|
|
210
235
|
const ptr = this.__destroy_into_raw();
|
|
211
|
-
wasm.
|
|
236
|
+
wasm.__wbg_rregex_free(ptr);
|
|
212
237
|
}
|
|
213
238
|
/**
|
|
239
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
240
|
+
* If an invalid expression is given, then an error is returned.
|
|
214
241
|
* @param {string} re
|
|
215
242
|
*/
|
|
216
243
|
constructor(re) {
|
|
217
244
|
var ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
218
245
|
var len0 = WASM_VECTOR_LEN;
|
|
219
|
-
var ret = wasm.
|
|
220
|
-
return
|
|
246
|
+
var ret = wasm.rregex_new(ptr0, len0);
|
|
247
|
+
return RRegex.__wrap(ret);
|
|
221
248
|
}
|
|
222
249
|
/**
|
|
250
|
+
* Returns true if and only if there is a match for the regex in the string given.
|
|
251
|
+
* 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.
|
|
252
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
223
253
|
* @param {string} text
|
|
224
254
|
* @returns {boolean}
|
|
225
255
|
*/
|
|
226
|
-
|
|
256
|
+
isMatch(text) {
|
|
227
257
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
228
258
|
var len0 = WASM_VECTOR_LEN;
|
|
229
|
-
var ret = wasm.
|
|
259
|
+
var ret = wasm.rregex_isMatch(this.ptr, ptr0, len0);
|
|
230
260
|
return ret !== 0;
|
|
231
261
|
}
|
|
232
262
|
/**
|
|
263
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
264
|
+
* 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`.
|
|
265
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
233
266
|
* @param {string} text
|
|
234
267
|
* @param {number} start
|
|
235
268
|
* @returns {boolean}
|
|
236
269
|
*/
|
|
237
|
-
|
|
270
|
+
isMatchAt(text, start) {
|
|
238
271
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
239
272
|
var len0 = WASM_VECTOR_LEN;
|
|
240
|
-
var ret = wasm.
|
|
273
|
+
var ret = wasm.rregex_isMatchAt(this.ptr, ptr0, len0, start);
|
|
241
274
|
return ret !== 0;
|
|
242
275
|
}
|
|
243
276
|
/**
|
|
277
|
+
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
278
|
+
* 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`.
|
|
279
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
244
280
|
* @param {string} text
|
|
245
281
|
* @returns {any}
|
|
246
282
|
*/
|
|
247
283
|
find(text) {
|
|
248
284
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
249
285
|
var len0 = WASM_VECTOR_LEN;
|
|
250
|
-
var ret = wasm.
|
|
286
|
+
var ret = wasm.rregex_find(this.ptr, ptr0, len0);
|
|
251
287
|
return takeObject(ret);
|
|
252
288
|
}
|
|
253
289
|
/**
|
|
290
|
+
* Returns the same as find, but starts the search at the given offset.
|
|
291
|
+
* 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`.
|
|
292
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
254
293
|
* @param {string} text
|
|
255
294
|
* @param {number} start
|
|
256
295
|
* @returns {any}
|
|
257
296
|
*/
|
|
258
|
-
|
|
297
|
+
findAt(text, start) {
|
|
259
298
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
260
299
|
var len0 = WASM_VECTOR_LEN;
|
|
261
|
-
var ret = wasm.
|
|
300
|
+
var ret = wasm.rregex_findAt(this.ptr, ptr0, len0, start);
|
|
262
301
|
return takeObject(ret);
|
|
263
302
|
}
|
|
264
303
|
/**
|
|
304
|
+
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
305
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
265
306
|
* @param {string} text
|
|
266
307
|
* @returns {any}
|
|
267
308
|
*/
|
|
268
|
-
|
|
309
|
+
findAll(text) {
|
|
269
310
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
270
311
|
var len0 = WASM_VECTOR_LEN;
|
|
271
|
-
var ret = wasm.
|
|
312
|
+
var ret = wasm.rregex_findAll(this.ptr, ptr0, len0);
|
|
272
313
|
return takeObject(ret);
|
|
273
314
|
}
|
|
274
315
|
/**
|
|
316
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
317
|
+
* 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.
|
|
318
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
319
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
275
320
|
* @param {string} text
|
|
276
321
|
* @param {string} rep
|
|
277
322
|
* @returns {string}
|
|
@@ -283,7 +328,7 @@ export class RRegExp {
|
|
|
283
328
|
var len0 = WASM_VECTOR_LEN;
|
|
284
329
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
285
330
|
var len1 = WASM_VECTOR_LEN;
|
|
286
|
-
wasm.
|
|
331
|
+
wasm.rregex_replace(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
287
332
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
288
333
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
289
334
|
return getStringFromWasm0(r0, r1);
|
|
@@ -293,6 +338,9 @@ export class RRegExp {
|
|
|
293
338
|
}
|
|
294
339
|
}
|
|
295
340
|
/**
|
|
341
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
342
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
343
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
296
344
|
* @param {string} text
|
|
297
345
|
* @param {number} limit
|
|
298
346
|
* @param {string} rep
|
|
@@ -305,7 +353,7 @@ export class RRegExp {
|
|
|
305
353
|
var len0 = WASM_VECTOR_LEN;
|
|
306
354
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
307
355
|
var len1 = WASM_VECTOR_LEN;
|
|
308
|
-
wasm.
|
|
356
|
+
wasm.rregex_replacen(retptr, this.ptr, ptr0, len0, limit, ptr1, len1);
|
|
309
357
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
310
358
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
311
359
|
return getStringFromWasm0(r0, r1);
|
|
@@ -315,18 +363,21 @@ export class RRegExp {
|
|
|
315
363
|
}
|
|
316
364
|
}
|
|
317
365
|
/**
|
|
366
|
+
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
367
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
368
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
318
369
|
* @param {string} text
|
|
319
370
|
* @param {string} rep
|
|
320
371
|
* @returns {string}
|
|
321
372
|
*/
|
|
322
|
-
|
|
373
|
+
replaceAll(text, rep) {
|
|
323
374
|
try {
|
|
324
375
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
325
376
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
326
377
|
var len0 = WASM_VECTOR_LEN;
|
|
327
378
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
328
379
|
var len1 = WASM_VECTOR_LEN;
|
|
329
|
-
wasm.
|
|
380
|
+
wasm.rregex_replaceAll(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
330
381
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
331
382
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
332
383
|
return getStringFromWasm0(r0, r1);
|
|
@@ -336,16 +387,22 @@ export class RRegExp {
|
|
|
336
387
|
}
|
|
337
388
|
}
|
|
338
389
|
/**
|
|
390
|
+
* 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.
|
|
391
|
+
* This method will not copy the text given.
|
|
392
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
339
393
|
* @param {string} text
|
|
340
394
|
* @returns {any}
|
|
341
395
|
*/
|
|
342
396
|
split(text) {
|
|
343
397
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
344
398
|
var len0 = WASM_VECTOR_LEN;
|
|
345
|
-
var ret = wasm.
|
|
399
|
+
var ret = wasm.rregex_split(this.ptr, ptr0, len0);
|
|
346
400
|
return takeObject(ret);
|
|
347
401
|
}
|
|
348
402
|
/**
|
|
403
|
+
* 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.
|
|
404
|
+
* This method will not copy the text given.
|
|
405
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
349
406
|
* @param {string} text
|
|
350
407
|
* @param {number} limit
|
|
351
408
|
* @returns {any}
|
|
@@ -353,14 +410,136 @@ export class RRegExp {
|
|
|
353
410
|
splitn(text, limit) {
|
|
354
411
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
355
412
|
var len0 = WASM_VECTOR_LEN;
|
|
356
|
-
var ret = wasm.
|
|
413
|
+
var ret = wasm.rregex_splitn(this.ptr, ptr0, len0, limit);
|
|
357
414
|
return takeObject(ret);
|
|
358
415
|
}
|
|
359
416
|
/**
|
|
417
|
+
* Returns the end location of a match in the text given.
|
|
418
|
+
* 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.
|
|
419
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
420
|
+
* @param {string} text
|
|
421
|
+
* @returns {number | undefined}
|
|
422
|
+
*/
|
|
423
|
+
shortestMatch(text) {
|
|
424
|
+
try {
|
|
425
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
426
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
427
|
+
var len0 = WASM_VECTOR_LEN;
|
|
428
|
+
wasm.rregex_shortestMatch(retptr, this.ptr, ptr0, len0);
|
|
429
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
430
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
431
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
432
|
+
} finally {
|
|
433
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
438
|
+
* 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`.
|
|
439
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
440
|
+
* @param {string} text
|
|
441
|
+
* @param {number} limit
|
|
442
|
+
* @returns {number | undefined}
|
|
443
|
+
*/
|
|
444
|
+
shortestMatchAt(text, limit) {
|
|
445
|
+
try {
|
|
446
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
447
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
448
|
+
var len0 = WASM_VECTOR_LEN;
|
|
449
|
+
wasm.rregex_shortestMatchAt(retptr, this.ptr, ptr0, len0, limit);
|
|
450
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
451
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
452
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
453
|
+
} finally {
|
|
454
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Return the Regex syntax object
|
|
360
459
|
* @returns {any}
|
|
361
460
|
*/
|
|
362
461
|
syntax() {
|
|
363
|
-
var ret = wasm.
|
|
462
|
+
var ret = wasm.rregex_syntax(this.ptr);
|
|
463
|
+
return takeObject(ret);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Returns a string representing the regular expression
|
|
467
|
+
* @returns {string}
|
|
468
|
+
*/
|
|
469
|
+
toString() {
|
|
470
|
+
try {
|
|
471
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
472
|
+
wasm.rregex_toString(retptr, this.ptr);
|
|
473
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
474
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
475
|
+
return getStringFromWasm0(r0, r1);
|
|
476
|
+
} finally {
|
|
477
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
478
|
+
wasm.__wbindgen_free(r0, r1);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
484
|
+
* 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.
|
|
485
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
486
|
+
*/
|
|
487
|
+
export class RRegexSet {
|
|
488
|
+
|
|
489
|
+
static __wrap(ptr) {
|
|
490
|
+
const obj = Object.create(RRegexSet.prototype);
|
|
491
|
+
obj.ptr = ptr;
|
|
492
|
+
|
|
493
|
+
return obj;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
__destroy_into_raw() {
|
|
497
|
+
const ptr = this.ptr;
|
|
498
|
+
this.ptr = 0;
|
|
499
|
+
|
|
500
|
+
return ptr;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
free() {
|
|
504
|
+
const ptr = this.__destroy_into_raw();
|
|
505
|
+
wasm.__wbg_rregexset_free(ptr);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Create a new regex set with the given regular expressions.
|
|
509
|
+
* @param {Array<any>} list
|
|
510
|
+
*/
|
|
511
|
+
constructor(list) {
|
|
512
|
+
try {
|
|
513
|
+
var ret = wasm.rregexset_new(addBorrowedObject(list));
|
|
514
|
+
return RRegexSet.__wrap(ret);
|
|
515
|
+
} finally {
|
|
516
|
+
heap[stack_pointer++] = undefined;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
521
|
+
* 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.
|
|
522
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
523
|
+
* @param {string} text
|
|
524
|
+
* @returns {boolean}
|
|
525
|
+
*/
|
|
526
|
+
isMatch(text) {
|
|
527
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
528
|
+
var len0 = WASM_VECTOR_LEN;
|
|
529
|
+
var ret = wasm.rregexset_isMatch(this.ptr, ptr0, len0);
|
|
530
|
+
return ret !== 0;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Returns the set of regular expressions that match in the given text.
|
|
534
|
+
* 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.
|
|
535
|
+
* the set can also be used to iterate over the matched indices.
|
|
536
|
+
* @param {string} text
|
|
537
|
+
* @returns {any}
|
|
538
|
+
*/
|
|
539
|
+
matches(text) {
|
|
540
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
541
|
+
var len0 = WASM_VECTOR_LEN;
|
|
542
|
+
var ret = wasm.rregexset_matches(this.ptr, ptr0, len0);
|
|
364
543
|
return takeObject(ret);
|
|
365
544
|
}
|
|
366
545
|
}
|
|
@@ -398,7 +577,7 @@ async function load(module, imports) {
|
|
|
398
577
|
|
|
399
578
|
async function init(input) {
|
|
400
579
|
if (typeof input === 'undefined') {
|
|
401
|
-
input = new URL('
|
|
580
|
+
input = new URL('rregex.wasm', import.meta.url);
|
|
402
581
|
}
|
|
403
582
|
const imports = {};
|
|
404
583
|
imports.wbg = {};
|
|
@@ -413,6 +592,26 @@ async function init(input) {
|
|
|
413
592
|
var ret = arg0;
|
|
414
593
|
return addHeapObject(ret);
|
|
415
594
|
};
|
|
595
|
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
596
|
+
var ret = typeof(getObject(arg0)) === 'string';
|
|
597
|
+
return ret;
|
|
598
|
+
};
|
|
599
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
600
|
+
const obj = getObject(arg1);
|
|
601
|
+
var ret = typeof(obj) === 'string' ? obj : undefined;
|
|
602
|
+
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
603
|
+
var len0 = WASM_VECTOR_LEN;
|
|
604
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
605
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
606
|
+
};
|
|
607
|
+
imports.wbg.__wbg_get_67189fe0b323d288 = function(arg0, arg1) {
|
|
608
|
+
var ret = getObject(arg0)[arg1 >>> 0];
|
|
609
|
+
return addHeapObject(ret);
|
|
610
|
+
};
|
|
611
|
+
imports.wbg.__wbg_length_42e02f5a04d67464 = function(arg0) {
|
|
612
|
+
var ret = getObject(arg0).length;
|
|
613
|
+
return ret;
|
|
614
|
+
};
|
|
416
615
|
imports.wbg.__wbg_new_949bbc1147195c4e = function() {
|
|
417
616
|
var ret = new Array();
|
|
418
617
|
return addHeapObject(ret);
|
|
@@ -463,3 +662,15 @@ async function init(input) {
|
|
|
463
662
|
|
|
464
663
|
export default init;
|
|
465
664
|
|
|
665
|
+
|
|
666
|
+
export const metadata = {
|
|
667
|
+
"name": "rregex",
|
|
668
|
+
"description": "Rust Regex binding for Javascript",
|
|
669
|
+
"authors": [
|
|
670
|
+
"Fede Ramirez <i@2fd.me>"
|
|
671
|
+
],
|
|
672
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
673
|
+
"repository": "https://github.com/2fd/rregex",
|
|
674
|
+
"regex": "1.1.9",
|
|
675
|
+
"regex-syntax": "0.6.25"
|
|
676
|
+
}
|