rregex 1.0.0 → 1.0.4
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/lib/browser.d.ts +471 -26
- package/lib/browser.js +297 -86
- package/lib/commonjs.d.ts +450 -12
- package/lib/commonjs.js +304 -88
- package/lib/module.d.ts +450 -12
- package/lib/module.js +291 -88
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +21 -14
- package/lib/types.d.ts +471 -26
- package/package.json +27 -4
package/lib/commonjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let imports = {};
|
|
2
|
-
imports['
|
|
2
|
+
imports['wbg'] = module.exports;
|
|
3
3
|
let wasm;
|
|
4
4
|
const { TextDecoder, TextEncoder } = require(`util`);
|
|
5
5
|
|
|
@@ -48,6 +48,73 @@ function addHeapObject(obj) {
|
|
|
48
48
|
return idx;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
let WASM_VECTOR_LEN = 0;
|
|
52
|
+
|
|
53
|
+
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
54
|
+
|
|
55
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
56
|
+
? function (arg, view) {
|
|
57
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
58
|
+
}
|
|
59
|
+
: function (arg, view) {
|
|
60
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
61
|
+
view.set(buf);
|
|
62
|
+
return {
|
|
63
|
+
read: arg.length,
|
|
64
|
+
written: buf.length
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
69
|
+
|
|
70
|
+
if (realloc === undefined) {
|
|
71
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
72
|
+
const ptr = malloc(buf.length);
|
|
73
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
74
|
+
WASM_VECTOR_LEN = buf.length;
|
|
75
|
+
return ptr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let len = arg.length;
|
|
79
|
+
let ptr = malloc(len);
|
|
80
|
+
|
|
81
|
+
const mem = getUint8Memory0();
|
|
82
|
+
|
|
83
|
+
let offset = 0;
|
|
84
|
+
|
|
85
|
+
for (; offset < len; offset++) {
|
|
86
|
+
const code = arg.charCodeAt(offset);
|
|
87
|
+
if (code > 0x7F) break;
|
|
88
|
+
mem[ptr + offset] = code;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (offset !== len) {
|
|
92
|
+
if (offset !== 0) {
|
|
93
|
+
arg = arg.slice(offset);
|
|
94
|
+
}
|
|
95
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
96
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
97
|
+
const ret = encodeString(arg, view);
|
|
98
|
+
|
|
99
|
+
offset += ret.written;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
WASM_VECTOR_LEN = offset;
|
|
103
|
+
return ptr;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isLikeNone(x) {
|
|
107
|
+
return x === undefined || x === null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let cachegetInt32Memory0 = null;
|
|
111
|
+
function getInt32Memory0() {
|
|
112
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
113
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
114
|
+
}
|
|
115
|
+
return cachegetInt32Memory0;
|
|
116
|
+
}
|
|
117
|
+
|
|
51
118
|
function debugString(val) {
|
|
52
119
|
// primitive types
|
|
53
120
|
const type = typeof val;
|
|
@@ -113,74 +180,30 @@ function debugString(val) {
|
|
|
113
180
|
return className;
|
|
114
181
|
}
|
|
115
182
|
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
183
|
+
let stack_pointer = 32;
|
|
119
184
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
: function (arg, view) {
|
|
125
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
126
|
-
view.set(buf);
|
|
127
|
-
return {
|
|
128
|
-
read: arg.length,
|
|
129
|
-
written: buf.length
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
134
|
-
|
|
135
|
-
if (realloc === undefined) {
|
|
136
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
137
|
-
const ptr = malloc(buf.length);
|
|
138
|
-
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
139
|
-
WASM_VECTOR_LEN = buf.length;
|
|
140
|
-
return ptr;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let len = arg.length;
|
|
144
|
-
let ptr = malloc(len);
|
|
145
|
-
|
|
146
|
-
const mem = getUint8Memory0();
|
|
147
|
-
|
|
148
|
-
let offset = 0;
|
|
149
|
-
|
|
150
|
-
for (; offset < len; offset++) {
|
|
151
|
-
const code = arg.charCodeAt(offset);
|
|
152
|
-
if (code > 0x7F) break;
|
|
153
|
-
mem[ptr + offset] = code;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (offset !== len) {
|
|
157
|
-
if (offset !== 0) {
|
|
158
|
-
arg = arg.slice(offset);
|
|
159
|
-
}
|
|
160
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
161
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
162
|
-
const ret = encodeString(arg, view);
|
|
163
|
-
|
|
164
|
-
offset += ret.written;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
WASM_VECTOR_LEN = offset;
|
|
168
|
-
return ptr;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let cachegetInt32Memory0 = null;
|
|
172
|
-
function getInt32Memory0() {
|
|
173
|
-
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
174
|
-
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
175
|
-
}
|
|
176
|
-
return cachegetInt32Memory0;
|
|
185
|
+
function addBorrowedObject(obj) {
|
|
186
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
187
|
+
heap[--stack_pointer] = obj;
|
|
188
|
+
return stack_pointer;
|
|
177
189
|
}
|
|
178
190
|
/**
|
|
179
|
-
* @
|
|
191
|
+
* @param {string} text
|
|
192
|
+
* @returns {string}
|
|
180
193
|
*/
|
|
181
|
-
module.exports.
|
|
182
|
-
|
|
183
|
-
|
|
194
|
+
module.exports.escape = function(text) {
|
|
195
|
+
try {
|
|
196
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
197
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
198
|
+
var len0 = WASM_VECTOR_LEN;
|
|
199
|
+
wasm.escape(retptr, ptr0, len0);
|
|
200
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
201
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
202
|
+
return getStringFromWasm0(r0, r1);
|
|
203
|
+
} finally {
|
|
204
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
205
|
+
wasm.__wbindgen_free(r0, r1);
|
|
206
|
+
}
|
|
184
207
|
};
|
|
185
208
|
|
|
186
209
|
function handleError(f, args) {
|
|
@@ -191,11 +214,13 @@ function handleError(f, args) {
|
|
|
191
214
|
}
|
|
192
215
|
}
|
|
193
216
|
/**
|
|
217
|
+
* A compiled regular expression for matching Unicode strings.
|
|
218
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
194
219
|
*/
|
|
195
|
-
class
|
|
220
|
+
class RRegex {
|
|
196
221
|
|
|
197
222
|
static __wrap(ptr) {
|
|
198
|
-
const obj = Object.create(
|
|
223
|
+
const obj = Object.create(RRegex.prototype);
|
|
199
224
|
obj.ptr = ptr;
|
|
200
225
|
|
|
201
226
|
return obj;
|
|
@@ -210,70 +235,90 @@ class RRegExp {
|
|
|
210
235
|
|
|
211
236
|
free() {
|
|
212
237
|
const ptr = this.__destroy_into_raw();
|
|
213
|
-
wasm.
|
|
238
|
+
wasm.__wbg_rregex_free(ptr);
|
|
214
239
|
}
|
|
215
240
|
/**
|
|
241
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
242
|
+
* If an invalid expression is given, then an error is returned.
|
|
216
243
|
* @param {string} re
|
|
217
244
|
*/
|
|
218
245
|
constructor(re) {
|
|
219
246
|
var ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
220
247
|
var len0 = WASM_VECTOR_LEN;
|
|
221
|
-
var ret = wasm.
|
|
222
|
-
return
|
|
248
|
+
var ret = wasm.rregex_new(ptr0, len0);
|
|
249
|
+
return RRegex.__wrap(ret);
|
|
223
250
|
}
|
|
224
251
|
/**
|
|
252
|
+
* Returns true if and only if there is a match for the regex in the string given.
|
|
253
|
+
* 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.
|
|
254
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
225
255
|
* @param {string} text
|
|
226
256
|
* @returns {boolean}
|
|
227
257
|
*/
|
|
228
|
-
|
|
258
|
+
isMatch(text) {
|
|
229
259
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
230
260
|
var len0 = WASM_VECTOR_LEN;
|
|
231
|
-
var ret = wasm.
|
|
261
|
+
var ret = wasm.rregex_isMatch(this.ptr, ptr0, len0);
|
|
232
262
|
return ret !== 0;
|
|
233
263
|
}
|
|
234
264
|
/**
|
|
265
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
266
|
+
* 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`.
|
|
267
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
235
268
|
* @param {string} text
|
|
236
269
|
* @param {number} start
|
|
237
270
|
* @returns {boolean}
|
|
238
271
|
*/
|
|
239
|
-
|
|
272
|
+
isMatchAt(text, start) {
|
|
240
273
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
241
274
|
var len0 = WASM_VECTOR_LEN;
|
|
242
|
-
var ret = wasm.
|
|
275
|
+
var ret = wasm.rregex_isMatchAt(this.ptr, ptr0, len0, start);
|
|
243
276
|
return ret !== 0;
|
|
244
277
|
}
|
|
245
278
|
/**
|
|
279
|
+
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
280
|
+
* 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`.
|
|
281
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
246
282
|
* @param {string} text
|
|
247
283
|
* @returns {any}
|
|
248
284
|
*/
|
|
249
285
|
find(text) {
|
|
250
286
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
251
287
|
var len0 = WASM_VECTOR_LEN;
|
|
252
|
-
var ret = wasm.
|
|
288
|
+
var ret = wasm.rregex_find(this.ptr, ptr0, len0);
|
|
253
289
|
return takeObject(ret);
|
|
254
290
|
}
|
|
255
291
|
/**
|
|
292
|
+
* Returns the same as find, but starts the search at the given offset.
|
|
293
|
+
* 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`.
|
|
294
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
256
295
|
* @param {string} text
|
|
257
296
|
* @param {number} start
|
|
258
297
|
* @returns {any}
|
|
259
298
|
*/
|
|
260
|
-
|
|
299
|
+
findAt(text, start) {
|
|
261
300
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
262
301
|
var len0 = WASM_VECTOR_LEN;
|
|
263
|
-
var ret = wasm.
|
|
302
|
+
var ret = wasm.rregex_findAt(this.ptr, ptr0, len0, start);
|
|
264
303
|
return takeObject(ret);
|
|
265
304
|
}
|
|
266
305
|
/**
|
|
306
|
+
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
307
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
267
308
|
* @param {string} text
|
|
268
309
|
* @returns {any}
|
|
269
310
|
*/
|
|
270
|
-
|
|
311
|
+
findAll(text) {
|
|
271
312
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
272
313
|
var len0 = WASM_VECTOR_LEN;
|
|
273
|
-
var ret = wasm.
|
|
314
|
+
var ret = wasm.rregex_findAll(this.ptr, ptr0, len0);
|
|
274
315
|
return takeObject(ret);
|
|
275
316
|
}
|
|
276
317
|
/**
|
|
318
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
319
|
+
* 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.
|
|
320
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
321
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
277
322
|
* @param {string} text
|
|
278
323
|
* @param {string} rep
|
|
279
324
|
* @returns {string}
|
|
@@ -285,7 +330,7 @@ class RRegExp {
|
|
|
285
330
|
var len0 = WASM_VECTOR_LEN;
|
|
286
331
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
287
332
|
var len1 = WASM_VECTOR_LEN;
|
|
288
|
-
wasm.
|
|
333
|
+
wasm.rregex_replace(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
289
334
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
290
335
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
291
336
|
return getStringFromWasm0(r0, r1);
|
|
@@ -295,6 +340,9 @@ class RRegExp {
|
|
|
295
340
|
}
|
|
296
341
|
}
|
|
297
342
|
/**
|
|
343
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
344
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
345
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
298
346
|
* @param {string} text
|
|
299
347
|
* @param {number} limit
|
|
300
348
|
* @param {string} rep
|
|
@@ -307,7 +355,7 @@ class RRegExp {
|
|
|
307
355
|
var len0 = WASM_VECTOR_LEN;
|
|
308
356
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
309
357
|
var len1 = WASM_VECTOR_LEN;
|
|
310
|
-
wasm.
|
|
358
|
+
wasm.rregex_replacen(retptr, this.ptr, ptr0, len0, limit, ptr1, len1);
|
|
311
359
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
312
360
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
313
361
|
return getStringFromWasm0(r0, r1);
|
|
@@ -317,18 +365,21 @@ class RRegExp {
|
|
|
317
365
|
}
|
|
318
366
|
}
|
|
319
367
|
/**
|
|
368
|
+
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
369
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
370
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
320
371
|
* @param {string} text
|
|
321
372
|
* @param {string} rep
|
|
322
373
|
* @returns {string}
|
|
323
374
|
*/
|
|
324
|
-
|
|
375
|
+
replaceAll(text, rep) {
|
|
325
376
|
try {
|
|
326
377
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
327
378
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
328
379
|
var len0 = WASM_VECTOR_LEN;
|
|
329
380
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
330
381
|
var len1 = WASM_VECTOR_LEN;
|
|
331
|
-
wasm.
|
|
382
|
+
wasm.rregex_replaceAll(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
332
383
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
333
384
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
334
385
|
return getStringFromWasm0(r0, r1);
|
|
@@ -338,16 +389,22 @@ class RRegExp {
|
|
|
338
389
|
}
|
|
339
390
|
}
|
|
340
391
|
/**
|
|
392
|
+
* 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.
|
|
393
|
+
* This method will not copy the text given.
|
|
394
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
341
395
|
* @param {string} text
|
|
342
396
|
* @returns {any}
|
|
343
397
|
*/
|
|
344
398
|
split(text) {
|
|
345
399
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
346
400
|
var len0 = WASM_VECTOR_LEN;
|
|
347
|
-
var ret = wasm.
|
|
401
|
+
var ret = wasm.rregex_split(this.ptr, ptr0, len0);
|
|
348
402
|
return takeObject(ret);
|
|
349
403
|
}
|
|
350
404
|
/**
|
|
405
|
+
* 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.
|
|
406
|
+
* This method will not copy the text given.
|
|
407
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
351
408
|
* @param {string} text
|
|
352
409
|
* @param {number} limit
|
|
353
410
|
* @returns {any}
|
|
@@ -355,18 +412,141 @@ class RRegExp {
|
|
|
355
412
|
splitn(text, limit) {
|
|
356
413
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
357
414
|
var len0 = WASM_VECTOR_LEN;
|
|
358
|
-
var ret = wasm.
|
|
415
|
+
var ret = wasm.rregex_splitn(this.ptr, ptr0, len0, limit);
|
|
359
416
|
return takeObject(ret);
|
|
360
417
|
}
|
|
361
418
|
/**
|
|
419
|
+
* Returns the end location of a match in the text given.
|
|
420
|
+
* 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.
|
|
421
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
422
|
+
* @param {string} text
|
|
423
|
+
* @returns {number | undefined}
|
|
424
|
+
*/
|
|
425
|
+
shortestMatch(text) {
|
|
426
|
+
try {
|
|
427
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
428
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
429
|
+
var len0 = WASM_VECTOR_LEN;
|
|
430
|
+
wasm.rregex_shortestMatch(retptr, this.ptr, ptr0, len0);
|
|
431
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
432
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
433
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
434
|
+
} finally {
|
|
435
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
440
|
+
* 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`.
|
|
441
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
442
|
+
* @param {string} text
|
|
443
|
+
* @param {number} limit
|
|
444
|
+
* @returns {number | undefined}
|
|
445
|
+
*/
|
|
446
|
+
shortestMatchAt(text, limit) {
|
|
447
|
+
try {
|
|
448
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
449
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
450
|
+
var len0 = WASM_VECTOR_LEN;
|
|
451
|
+
wasm.rregex_shortestMatchAt(retptr, this.ptr, ptr0, len0, limit);
|
|
452
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
453
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
454
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
455
|
+
} finally {
|
|
456
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Return the Regex syntax object
|
|
362
461
|
* @returns {any}
|
|
363
462
|
*/
|
|
364
463
|
syntax() {
|
|
365
|
-
var ret = wasm.
|
|
464
|
+
var ret = wasm.rregex_syntax(this.ptr);
|
|
366
465
|
return takeObject(ret);
|
|
367
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Returns a string representing the regular expression
|
|
469
|
+
* @returns {string}
|
|
470
|
+
*/
|
|
471
|
+
toString() {
|
|
472
|
+
try {
|
|
473
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
474
|
+
wasm.rregex_toString(retptr, this.ptr);
|
|
475
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
476
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
477
|
+
return getStringFromWasm0(r0, r1);
|
|
478
|
+
} finally {
|
|
479
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
480
|
+
wasm.__wbindgen_free(r0, r1);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
368
483
|
}
|
|
369
|
-
module.exports.
|
|
484
|
+
module.exports.RRegex = RRegex;
|
|
485
|
+
/**
|
|
486
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
487
|
+
* 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.
|
|
488
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
489
|
+
*/
|
|
490
|
+
class RRegexSet {
|
|
491
|
+
|
|
492
|
+
static __wrap(ptr) {
|
|
493
|
+
const obj = Object.create(RRegexSet.prototype);
|
|
494
|
+
obj.ptr = ptr;
|
|
495
|
+
|
|
496
|
+
return obj;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
__destroy_into_raw() {
|
|
500
|
+
const ptr = this.ptr;
|
|
501
|
+
this.ptr = 0;
|
|
502
|
+
|
|
503
|
+
return ptr;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
free() {
|
|
507
|
+
const ptr = this.__destroy_into_raw();
|
|
508
|
+
wasm.__wbg_rregexset_free(ptr);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Create a new regex set with the given regular expressions.
|
|
512
|
+
* @param {Array<any>} list
|
|
513
|
+
*/
|
|
514
|
+
constructor(list) {
|
|
515
|
+
try {
|
|
516
|
+
var ret = wasm.rregexset_new(addBorrowedObject(list));
|
|
517
|
+
return RRegexSet.__wrap(ret);
|
|
518
|
+
} finally {
|
|
519
|
+
heap[stack_pointer++] = undefined;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
524
|
+
* 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.
|
|
525
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
526
|
+
* @param {string} text
|
|
527
|
+
* @returns {boolean}
|
|
528
|
+
*/
|
|
529
|
+
isMatch(text) {
|
|
530
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
531
|
+
var len0 = WASM_VECTOR_LEN;
|
|
532
|
+
var ret = wasm.rregexset_isMatch(this.ptr, ptr0, len0);
|
|
533
|
+
return ret !== 0;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Returns the set of regular expressions that match in the given text.
|
|
537
|
+
* 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.
|
|
538
|
+
* the set can also be used to iterate over the matched indices.
|
|
539
|
+
* @param {string} text
|
|
540
|
+
* @returns {any}
|
|
541
|
+
*/
|
|
542
|
+
matches(text) {
|
|
543
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
544
|
+
var len0 = WASM_VECTOR_LEN;
|
|
545
|
+
var ret = wasm.rregexset_matches(this.ptr, ptr0, len0);
|
|
546
|
+
return takeObject(ret);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
module.exports.RRegexSet = RRegexSet;
|
|
370
550
|
|
|
371
551
|
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
372
552
|
takeObject(arg0);
|
|
@@ -382,6 +562,30 @@ module.exports.__wbindgen_number_new = function(arg0) {
|
|
|
382
562
|
return addHeapObject(ret);
|
|
383
563
|
};
|
|
384
564
|
|
|
565
|
+
module.exports.__wbindgen_is_string = function(arg0) {
|
|
566
|
+
var ret = typeof(getObject(arg0)) === 'string';
|
|
567
|
+
return ret;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
571
|
+
const obj = getObject(arg1);
|
|
572
|
+
var ret = typeof(obj) === 'string' ? obj : undefined;
|
|
573
|
+
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
574
|
+
var len0 = WASM_VECTOR_LEN;
|
|
575
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
576
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
module.exports.__wbg_get_67189fe0b323d288 = function(arg0, arg1) {
|
|
580
|
+
var ret = getObject(arg0)[arg1 >>> 0];
|
|
581
|
+
return addHeapObject(ret);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
module.exports.__wbg_length_42e02f5a04d67464 = function(arg0) {
|
|
585
|
+
var ret = getObject(arg0).length;
|
|
586
|
+
return ret;
|
|
587
|
+
};
|
|
588
|
+
|
|
385
589
|
module.exports.__wbg_new_949bbc1147195c4e = function() {
|
|
386
590
|
var ret = new Array();
|
|
387
591
|
return addHeapObject(ret);
|
|
@@ -423,7 +627,7 @@ module.exports.__wbindgen_rethrow = function(arg0) {
|
|
|
423
627
|
throw takeObject(arg0);
|
|
424
628
|
};
|
|
425
629
|
|
|
426
|
-
const path = require('path').join(__dirname, '
|
|
630
|
+
const path = require('path').join(__dirname, 'rregex.wasm');
|
|
427
631
|
const bytes = require('fs').readFileSync(path);
|
|
428
632
|
|
|
429
633
|
const wasmModule = new WebAssembly.Module(bytes);
|
|
@@ -431,3 +635,15 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
|
431
635
|
wasm = wasmInstance.exports;
|
|
432
636
|
module.exports.__wasm = wasm;
|
|
433
637
|
|
|
638
|
+
|
|
639
|
+
module.exports.metadata = {
|
|
640
|
+
"name": "rregex",
|
|
641
|
+
"description": "Rust Regex binding for Javascript",
|
|
642
|
+
"authors": [
|
|
643
|
+
"Fede Ramirez <i@2fd.me>"
|
|
644
|
+
],
|
|
645
|
+
"homepage": "https://2fd.github.io/rregex",
|
|
646
|
+
"repository": "https://github.com/2fd/rregex",
|
|
647
|
+
"regex": "1.0.6",
|
|
648
|
+
"regex-syntax": "0.6.25"
|
|
649
|
+
}
|