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