rregex 1.10.11 → 1.10.13
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 +31 -5
- package/lib/cf.d.ts +655 -658
- package/lib/cf.mjs +2 -2
- package/lib/commonjs.cjs +797 -950
- package/lib/commonjs.d.cts +1257 -0
- package/lib/esm.d.ts +621 -628
- package/lib/esm.mjs +799 -951
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +34 -30
- package/lib/standalone.d.ts +653 -656
- package/lib/standalone.js +1009 -1146
- package/lib/types.d.ts +655 -658
- package/lib/web.d.ts +655 -658
- package/lib/web.js +826 -963
- package/package.json +38 -4
- package/img/rregex-vs-native_-email.png +0 -0
- package/img/rregex-vs-native_-ip.png +0 -0
- package/img/rregex-vs-native_-simple-ip.png +0 -0
- package/img/rregex-vs-native_-uri.png +0 -0
- package/lib/commonjs.d.ts +0 -1264
package/lib/standalone.js
CHANGED
|
@@ -7,1277 +7,1140 @@ let wasm_bindgen;
|
|
|
7
7
|
}
|
|
8
8
|
let wasm = undefined;
|
|
9
9
|
|
|
10
|
+
function addToExternrefTable0(obj) {
|
|
11
|
+
const idx = wasm.__externref_table_alloc();
|
|
12
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
13
|
+
return idx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function handleError(f, args) {
|
|
17
|
+
try {
|
|
18
|
+
return f.apply(this, args);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
const idx = addToExternrefTable0(e);
|
|
21
|
+
wasm.__wbindgen_exn_store(idx);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
11
26
|
|
|
12
27
|
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
13
28
|
|
|
14
|
-
let
|
|
29
|
+
let cachedUint8ArrayMemory0 = null;
|
|
15
30
|
|
|
16
|
-
function
|
|
17
|
-
if (
|
|
18
|
-
|
|
31
|
+
function getUint8ArrayMemory0() {
|
|
32
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
33
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
19
34
|
}
|
|
20
|
-
return
|
|
35
|
+
return cachedUint8ArrayMemory0;
|
|
21
36
|
}
|
|
22
37
|
|
|
23
38
|
function getStringFromWasm0(ptr, len) {
|
|
24
39
|
ptr = ptr >>> 0;
|
|
25
|
-
return cachedTextDecoder.decode(
|
|
40
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
|
|
43
|
+
let WASM_VECTOR_LEN = 0;
|
|
29
44
|
|
|
30
|
-
|
|
45
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
36
|
-
const idx = heap_next;
|
|
37
|
-
heap_next = heap[idx];
|
|
38
|
-
|
|
39
|
-
heap[idx] = obj;
|
|
40
|
-
return idx;
|
|
47
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
48
|
+
? function (arg, view) {
|
|
49
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
41
50
|
}
|
|
42
|
-
|
|
43
|
-
function getObject(idx) { return heap[idx]; }
|
|
44
|
-
|
|
45
|
-
function dropObject(idx) {
|
|
46
|
-
if (idx < 132) return;
|
|
47
|
-
heap[idx] = heap_next;
|
|
48
|
-
heap_next = idx;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function takeObject(idx) {
|
|
52
|
-
const ret = getObject(idx);
|
|
53
|
-
dropObject(idx);
|
|
54
|
-
return ret;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let WASM_VECTOR_LEN = 0;
|
|
58
|
-
|
|
59
|
-
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
60
|
-
|
|
61
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
62
|
-
? function (arg, view) {
|
|
63
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
64
|
-
}
|
|
65
|
-
: function (arg, view) {
|
|
66
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
67
|
-
view.set(buf);
|
|
68
|
-
return {
|
|
69
|
-
read: arg.length,
|
|
70
|
-
written: buf.length
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
75
|
-
|
|
76
|
-
if (realloc === undefined) {
|
|
51
|
+
: function (arg, view) {
|
|
77
52
|
const buf = cachedTextEncoder.encode(arg);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (code > 0x7F) break;
|
|
94
|
-
mem[ptr + offset] = code;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (offset !== len) {
|
|
98
|
-
if (offset !== 0) {
|
|
99
|
-
arg = arg.slice(offset);
|
|
53
|
+
view.set(buf);
|
|
54
|
+
return {
|
|
55
|
+
read: arg.length,
|
|
56
|
+
written: buf.length
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
61
|
+
|
|
62
|
+
if (realloc === undefined) {
|
|
63
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
64
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
65
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
66
|
+
WASM_VECTOR_LEN = buf.length;
|
|
67
|
+
return ptr;
|
|
100
68
|
}
|
|
101
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
102
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
103
|
-
const ret = encodeString(arg, view);
|
|
104
69
|
|
|
105
|
-
|
|
106
|
-
ptr =
|
|
107
|
-
}
|
|
70
|
+
let len = arg.length;
|
|
71
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
108
72
|
|
|
109
|
-
|
|
110
|
-
return ptr;
|
|
111
|
-
}
|
|
73
|
+
const mem = getUint8ArrayMemory0();
|
|
112
74
|
|
|
113
|
-
|
|
114
|
-
return x === undefined || x === null;
|
|
115
|
-
}
|
|
75
|
+
let offset = 0;
|
|
116
76
|
|
|
117
|
-
|
|
77
|
+
for (; offset < len; offset++) {
|
|
78
|
+
const code = arg.charCodeAt(offset);
|
|
79
|
+
if (code > 0x7F) break;
|
|
80
|
+
mem[ptr + offset] = code;
|
|
81
|
+
}
|
|
118
82
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
83
|
+
if (offset !== len) {
|
|
84
|
+
if (offset !== 0) {
|
|
85
|
+
arg = arg.slice(offset);
|
|
86
|
+
}
|
|
87
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
88
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
89
|
+
const ret = encodeString(arg, view);
|
|
125
90
|
|
|
126
|
-
|
|
91
|
+
offset += ret.written;
|
|
92
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
93
|
+
}
|
|
127
94
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
95
|
+
WASM_VECTOR_LEN = offset;
|
|
96
|
+
return ptr;
|
|
131
97
|
}
|
|
132
|
-
return cachedUint32Memory0;
|
|
133
|
-
}
|
|
134
98
|
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
const mem = getUint32Memory0();
|
|
138
|
-
const slice = mem.subarray(ptr / 4, ptr / 4 + len);
|
|
139
|
-
const result = [];
|
|
140
|
-
for (let i = 0; i < slice.length; i++) {
|
|
141
|
-
result.push(takeObject(slice[i]));
|
|
99
|
+
function isLikeNone(x) {
|
|
100
|
+
return x === undefined || x === null;
|
|
142
101
|
}
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let stack_pointer = 128;
|
|
147
102
|
|
|
148
|
-
|
|
149
|
-
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
150
|
-
heap[--stack_pointer] = obj;
|
|
151
|
-
return stack_pointer;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Escapes all regular expression meta characters in `text`.
|
|
155
|
-
*
|
|
156
|
-
* The string returned may be safely used as a literal in a regular
|
|
157
|
-
* expression.
|
|
158
|
-
* @param {string} text
|
|
159
|
-
* @returns {string}
|
|
160
|
-
*/
|
|
161
|
-
__exports.escape = function(text) {
|
|
162
|
-
let deferred2_0;
|
|
163
|
-
let deferred2_1;
|
|
164
|
-
try {
|
|
165
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
166
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
167
|
-
const len0 = WASM_VECTOR_LEN;
|
|
168
|
-
wasm.escape(retptr, ptr0, len0);
|
|
169
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
170
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
171
|
-
deferred2_0 = r0;
|
|
172
|
-
deferred2_1 = r1;
|
|
173
|
-
return getStringFromWasm0(r0, r1);
|
|
174
|
-
} finally {
|
|
175
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
176
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
103
|
+
let cachedDataViewMemory0 = null;
|
|
179
104
|
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
105
|
+
function getDataViewMemory0() {
|
|
106
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
107
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
108
|
+
}
|
|
109
|
+
return cachedDataViewMemory0;
|
|
185
110
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
189
|
-
? { register: () => {}, unregister: () => {} }
|
|
190
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0));
|
|
191
|
-
/**
|
|
192
|
-
* A compiled regular expression for matching Unicode strings.
|
|
193
|
-
*
|
|
194
|
-
* A `RRegex` can be used to search haystacks, split haystacks into substrings
|
|
195
|
-
* or replace substrings in a haystack with a different substring. All
|
|
196
|
-
* searching is done with an implicit `(?s:.)*?` at the beginning and end of
|
|
197
|
-
* an pattern. To force an expression to match the whole string (or a prefix
|
|
198
|
-
* or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
|
|
199
|
-
*
|
|
200
|
-
* While this library will handle Unicode strings (whether in the regular
|
|
201
|
-
* expression or in the haystack), all positions returned are **byte
|
|
202
|
-
* offsets**. Every byte offset is guaranteed to be at a Unicode code point
|
|
203
|
-
* boundary. That is, all offsets returned by the `RRegex` API are guaranteed
|
|
204
|
-
* to be ranges that can slice an `Uint8Array` created with a TextEncoder.
|
|
205
|
-
*
|
|
206
|
-
* # Example: slicing over UTF strings
|
|
207
|
-
*
|
|
208
|
-
* ```typescript
|
|
209
|
-
* import { RRegex } from "rregex"
|
|
210
|
-
*
|
|
211
|
-
* const re = new RRegex("ä")
|
|
212
|
-
* const m = re.find("äöü") // { start: 0, end: 2 }
|
|
213
|
-
*
|
|
214
|
-
* const buff = new TextEncoder().encode("äöü")
|
|
215
|
-
* const slice = buff.slice(m.start, m.end)
|
|
216
|
-
* expect(new TextDecoder().decode(slice)).toBe("ä")
|
|
217
|
-
* ```
|
|
218
|
-
*
|
|
219
|
-
* # Example: find the offsets of a US phone number:
|
|
220
|
-
*
|
|
221
|
-
* ```typescript
|
|
222
|
-
* import { RRegex } from "rregex"
|
|
223
|
-
*
|
|
224
|
-
* const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
|
|
225
|
-
* const m = re.find("phone: 111-222-3333");
|
|
226
|
-
* expect(m.start).toBe(7);
|
|
227
|
-
* expect(m.end).toBe(19);
|
|
228
|
-
* ```
|
|
229
|
-
*
|
|
230
|
-
* @see https://docs.rs/regex/latest/regex/
|
|
231
|
-
*/
|
|
232
|
-
class RRegex {
|
|
233
111
|
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return ptr;
|
|
112
|
+
function takeFromExternrefTable0(idx) {
|
|
113
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
114
|
+
wasm.__externref_table_dealloc(idx);
|
|
115
|
+
return value;
|
|
239
116
|
}
|
|
240
117
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
* to search, split or replace text in a string.
|
|
248
|
-
*
|
|
249
|
-
* If an invalid expression is given, then an error is returned.
|
|
250
|
-
* @param {string} re
|
|
251
|
-
*/
|
|
252
|
-
constructor(re) {
|
|
253
|
-
try {
|
|
254
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
255
|
-
const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
256
|
-
const len0 = WASM_VECTOR_LEN;
|
|
257
|
-
wasm.rregex_new(retptr, ptr0, len0);
|
|
258
|
-
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
259
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
260
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
261
|
-
if (r2) {
|
|
262
|
-
throw takeObject(r1);
|
|
263
|
-
}
|
|
264
|
-
this.__wbg_ptr = r0 >>> 0;
|
|
265
|
-
return this;
|
|
266
|
-
} finally {
|
|
267
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
118
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
119
|
+
ptr = ptr >>> 0;
|
|
120
|
+
const mem = getDataViewMemory0();
|
|
121
|
+
const result = [];
|
|
122
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
123
|
+
result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
|
|
268
124
|
}
|
|
125
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
126
|
+
return result;
|
|
269
127
|
}
|
|
270
128
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
* Unicode word characters:
|
|
282
|
-
*
|
|
283
|
-
* ```typescript
|
|
284
|
-
* import { RRegex } from "rregex"
|
|
285
|
-
*
|
|
286
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
287
|
-
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
288
|
-
* ```
|
|
289
|
-
*
|
|
290
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
291
|
-
* @param {string} text - The string against which to match the regular expression
|
|
292
|
-
* @return {boolean}
|
|
293
|
-
*/
|
|
294
|
-
isMatch(text) {
|
|
295
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
296
|
-
const len0 = WASM_VECTOR_LEN;
|
|
297
|
-
const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
|
|
298
|
-
return ret !== 0;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Returns the same as is_match, but starts the search at the given offset.
|
|
302
|
-
* The significance of the starting point is that it takes the surrounding
|
|
303
|
-
* context into consideration. For example, the `\A` anchor can only match
|
|
304
|
-
* when `start == 0`.
|
|
305
|
-
*
|
|
306
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
307
|
-
* @param {string} text - The string against which to match the regular expression
|
|
308
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
309
|
-
* @return {boolean}
|
|
310
|
-
*/
|
|
311
|
-
isMatchAt(text, start) {
|
|
312
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
313
|
-
const len0 = WASM_VECTOR_LEN;
|
|
314
|
-
const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
|
|
315
|
-
return ret !== 0;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Returns the start and end byte range of the leftmost-first match in
|
|
319
|
-
* `text`. If no match exists, then `undefined` is returned.
|
|
320
|
-
*
|
|
321
|
-
* Note that this should only be used if you want to discover the position
|
|
322
|
-
* of the match. Testing the existence of a match is faster if you use
|
|
323
|
-
* `isMatch`.
|
|
324
|
-
*
|
|
325
|
-
* # Example
|
|
326
|
-
*
|
|
327
|
-
* Find the start and end location of the first word with exactly 13
|
|
328
|
-
* Unicode word characters:
|
|
329
|
-
*
|
|
330
|
-
* ```typescript
|
|
331
|
-
* import { RRegex } from "rregex"
|
|
332
|
-
*
|
|
333
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
334
|
-
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
335
|
-
* expect(m.start).toBe(2)
|
|
336
|
-
* expect(m.end).toBe(15)
|
|
337
|
-
* ```
|
|
338
|
-
*
|
|
339
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
340
|
-
* @param {string} text - The string against which to match the regular expression
|
|
341
|
-
* @return {Match}
|
|
342
|
-
*/
|
|
343
|
-
find(text) {
|
|
129
|
+
* Escapes all regular expression meta characters in `text`.
|
|
130
|
+
*
|
|
131
|
+
* The string returned may be safely used as a literal in a regular
|
|
132
|
+
* expression.
|
|
133
|
+
* @param {string} text
|
|
134
|
+
* @returns {string}
|
|
135
|
+
*/
|
|
136
|
+
__exports.escape = function(text) {
|
|
137
|
+
let deferred2_0;
|
|
138
|
+
let deferred2_1;
|
|
344
139
|
try {
|
|
345
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
346
140
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
347
141
|
const len0 = WASM_VECTOR_LEN;
|
|
348
|
-
wasm.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (r2) {
|
|
353
|
-
throw takeObject(r1);
|
|
354
|
-
}
|
|
355
|
-
return takeObject(r0);
|
|
142
|
+
const ret = wasm.escape(ptr0, len0);
|
|
143
|
+
deferred2_0 = ret[0];
|
|
144
|
+
deferred2_1 = ret[1];
|
|
145
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
356
146
|
} finally {
|
|
357
|
-
wasm.
|
|
147
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
358
148
|
}
|
|
359
|
-
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
152
|
+
? { register: () => {}, unregister: () => {} }
|
|
153
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0, 1));
|
|
360
154
|
/**
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
155
|
+
* A compiled regular expression for matching Unicode strings.
|
|
156
|
+
*
|
|
157
|
+
* A `RRegex` can be used to search haystacks, split haystacks into substrings
|
|
158
|
+
* or replace substrings in a haystack with a different substring. All
|
|
159
|
+
* searching is done with an implicit `(?s:.)*?` at the beginning and end of
|
|
160
|
+
* an pattern. To force an expression to match the whole string (or a prefix
|
|
161
|
+
* or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
|
|
162
|
+
*
|
|
163
|
+
* While this library will handle Unicode strings (whether in the regular
|
|
164
|
+
* expression or in the haystack), all positions returned are **byte
|
|
165
|
+
* offsets**. Every byte offset is guaranteed to be at a Unicode code point
|
|
166
|
+
* boundary. That is, all offsets returned by the `RRegex` API are guaranteed
|
|
167
|
+
* to be ranges that can slice an `Uint8Array` created with a TextEncoder.
|
|
168
|
+
*
|
|
169
|
+
* # Example: slicing over UTF strings
|
|
170
|
+
*
|
|
171
|
+
* ```typescript
|
|
172
|
+
* import { RRegex } from "rregex"
|
|
173
|
+
*
|
|
174
|
+
* const re = new RRegex("ä")
|
|
175
|
+
* const m = re.find("äöü") // { start: 0, end: 2 }
|
|
176
|
+
*
|
|
177
|
+
* const buff = new TextEncoder().encode("äöü")
|
|
178
|
+
* const slice = buff.slice(m.start, m.end)
|
|
179
|
+
* expect(new TextDecoder().decode(slice)).toBe("ä")
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* # Example: find the offsets of a US phone number:
|
|
183
|
+
*
|
|
184
|
+
* ```typescript
|
|
185
|
+
* import { RRegex } from "rregex"
|
|
186
|
+
*
|
|
187
|
+
* const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
|
|
188
|
+
* const m = re.find("phone: 111-222-3333");
|
|
189
|
+
* expect(m.start).toBe(7);
|
|
190
|
+
* expect(m.end).toBe(19);
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
194
|
+
*/
|
|
195
|
+
class RRegex {
|
|
196
|
+
|
|
197
|
+
__destroy_into_raw() {
|
|
198
|
+
const ptr = this.__wbg_ptr;
|
|
199
|
+
this.__wbg_ptr = 0;
|
|
200
|
+
RRegexFinalization.unregister(this);
|
|
201
|
+
return ptr;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
free() {
|
|
205
|
+
const ptr = this.__destroy_into_raw();
|
|
206
|
+
wasm.__wbg_rregex_free(ptr, 0);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
210
|
+
* The significance of the starting point is that it takes the surrounding
|
|
211
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
212
|
+
* when `start == 0`.
|
|
213
|
+
*
|
|
214
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
215
|
+
* @param {string} text - The string against which to match the regular expression
|
|
216
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
217
|
+
* @return {boolean}
|
|
218
|
+
*/
|
|
219
|
+
isMatchAt(text, start) {
|
|
376
220
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
377
221
|
const len0 = WASM_VECTOR_LEN;
|
|
378
|
-
wasm.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
222
|
+
const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
|
|
223
|
+
return ret !== 0;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
227
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
228
|
+
* `0`.
|
|
229
|
+
*
|
|
230
|
+
* See the documentation for `replace` for details on how to access
|
|
231
|
+
* capturing group matches in the replacement string.
|
|
232
|
+
*
|
|
233
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
234
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
235
|
+
* @param {string} text - The string against which to match the regular expression
|
|
236
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
237
|
+
* @returns {string}
|
|
238
|
+
*/
|
|
239
|
+
replaceAll(text, rep) {
|
|
240
|
+
let deferred3_0;
|
|
241
|
+
let deferred3_1;
|
|
242
|
+
try {
|
|
243
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
244
|
+
const len0 = WASM_VECTOR_LEN;
|
|
245
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
246
|
+
const len1 = WASM_VECTOR_LEN;
|
|
247
|
+
const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
248
|
+
deferred3_0 = ret[0];
|
|
249
|
+
deferred3_1 = ret[1];
|
|
250
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
251
|
+
} finally {
|
|
252
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
384
253
|
}
|
|
385
|
-
return takeObject(r0);
|
|
386
|
-
} finally {
|
|
387
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
388
254
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
257
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
258
|
+
* returns information about capturing group matches.
|
|
259
|
+
*
|
|
260
|
+
* # Example
|
|
261
|
+
*
|
|
262
|
+
* We can use this to find all movie titles and their release years in
|
|
263
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
264
|
+
*
|
|
265
|
+
* ```typescript
|
|
266
|
+
* import { RRegex } from "rregex"
|
|
267
|
+
*
|
|
268
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
269
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
270
|
+
* for caps of re.captures_iter(text) {
|
|
271
|
+
* console.log(
|
|
272
|
+
* "Movie:", caps.name["title"].value, ","
|
|
273
|
+
* "Released:", caps.name["year"].value
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* // Output:
|
|
277
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
278
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
279
|
+
* // Movie: M, Released: 1931
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
283
|
+
* @param {string} text - The string against which to match the regular expression
|
|
284
|
+
* @returns {Captures[]}
|
|
285
|
+
*/
|
|
286
|
+
capturesAll(text) {
|
|
413
287
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
414
288
|
const len0 = WASM_VECTOR_LEN;
|
|
415
|
-
wasm.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
419
|
-
if (r2) {
|
|
420
|
-
throw takeObject(r1);
|
|
289
|
+
const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
|
|
290
|
+
if (ret[2]) {
|
|
291
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
421
292
|
}
|
|
422
|
-
return
|
|
423
|
-
} finally {
|
|
424
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
293
|
+
return takeFromExternrefTable0(ret[0]);
|
|
425
294
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Returns the number of captures.
|
|
297
|
+
*
|
|
298
|
+
* This includes all named and unnamed groups, including the implicit
|
|
299
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
300
|
+
*
|
|
301
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
302
|
+
* length returned is guaranteed to be greater than zero.
|
|
303
|
+
*
|
|
304
|
+
* ## Example
|
|
305
|
+
*
|
|
306
|
+
* ```typescript
|
|
307
|
+
* import { RRegex } from "rregex"
|
|
308
|
+
*
|
|
309
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
310
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
311
|
+
*
|
|
312
|
+
* const re2 = new RRegex("foo")
|
|
313
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
314
|
+
*
|
|
315
|
+
* const re3 = new RRegex("(foo)")
|
|
316
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
317
|
+
*
|
|
318
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
319
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
320
|
+
*
|
|
321
|
+
* const re5 = new RRegex("[a&&b]")
|
|
322
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
326
|
+
* @returns {number}
|
|
327
|
+
*/
|
|
328
|
+
capturesLength() {
|
|
329
|
+
const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
|
|
330
|
+
return ret >>> 0;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Returns a list of the capture names in this regex.
|
|
334
|
+
*
|
|
335
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
336
|
+
*/
|
|
337
|
+
captureNames() {
|
|
338
|
+
const ret = wasm.rregex_captureNames(this.__wbg_ptr);
|
|
339
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
340
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
440
341
|
return v1;
|
|
441
|
-
} finally {
|
|
442
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
443
342
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
* import { RRegex } from "rregex"
|
|
479
|
-
*
|
|
480
|
-
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
481
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
482
|
-
* const caps = re.captures(text)
|
|
483
|
-
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
484
|
-
* expect(caps.name["year"].value).toBe("1941")
|
|
485
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
486
|
-
* ```
|
|
487
|
-
*
|
|
488
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
489
|
-
* @param {string} text - The string against which to match the regular expression
|
|
490
|
-
* @returns {Captures|undefined}
|
|
491
|
-
*/
|
|
492
|
-
captures(text) {
|
|
493
|
-
try {
|
|
494
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
343
|
+
/**
|
|
344
|
+
* Returns the end location of a match in the text given.
|
|
345
|
+
*
|
|
346
|
+
* This method may have the same performance characteristics as
|
|
347
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
348
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
349
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
350
|
+
*
|
|
351
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
352
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
353
|
+
* it returns the offset at the point at which the internal regex engine
|
|
354
|
+
* has determined that a match has occurred. This may vary depending on
|
|
355
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
356
|
+
* change.
|
|
357
|
+
*
|
|
358
|
+
* # Example
|
|
359
|
+
*
|
|
360
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
361
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
362
|
+
* `a`.
|
|
363
|
+
*
|
|
364
|
+
* ```typescript
|
|
365
|
+
* import { RRegex } from "rregex"
|
|
366
|
+
*
|
|
367
|
+
* const text = "aaaaa"
|
|
368
|
+
* const = new RRegex("a+").shortest_match(text)
|
|
369
|
+
* expect(pos).toBe(1)
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
373
|
+
* @param {string} text - The string against which to match the regular expression
|
|
374
|
+
* @returns {number|undefined}
|
|
375
|
+
*/
|
|
376
|
+
shortestMatch(text) {
|
|
495
377
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
496
378
|
const len0 = WASM_VECTOR_LEN;
|
|
497
|
-
wasm.
|
|
498
|
-
|
|
499
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
500
|
-
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
501
|
-
if (r2) {
|
|
502
|
-
throw takeObject(r1);
|
|
503
|
-
}
|
|
504
|
-
return takeObject(r0);
|
|
505
|
-
} finally {
|
|
506
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
379
|
+
const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
|
|
380
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
507
381
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
*
|
|
522
|
-
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
523
|
-
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
524
|
-
* for caps of re.captures_iter(text) {
|
|
525
|
-
* console.log(
|
|
526
|
-
* "Movie:", caps.name["title"].value, ","
|
|
527
|
-
* "Released:", caps.name["year"].value
|
|
528
|
-
* );
|
|
529
|
-
* }
|
|
530
|
-
* // Output:
|
|
531
|
-
* // Movie: Citizen Kane, Released: 1941
|
|
532
|
-
* // Movie: The Wizard of Oz, Released: 1939
|
|
533
|
-
* // Movie: M, Released: 1931
|
|
534
|
-
* ```
|
|
535
|
-
*
|
|
536
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
537
|
-
* @param {string} text - The string against which to match the regular expression
|
|
538
|
-
* @returns {Captures[]}
|
|
539
|
-
*/
|
|
540
|
-
capturesAll(text) {
|
|
541
|
-
try {
|
|
542
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
382
|
+
/**
|
|
383
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
384
|
+
* given offset.
|
|
385
|
+
*
|
|
386
|
+
* The significance of the starting point is that it takes the surrounding
|
|
387
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
388
|
+
* when `start == 0`.
|
|
389
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
390
|
+
* @param {string} text - The string against which to match the regular expression
|
|
391
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
392
|
+
* @returns {number|undefined}
|
|
393
|
+
*/
|
|
394
|
+
shortestMatchAt(text, start) {
|
|
543
395
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
544
396
|
const len0 = WASM_VECTOR_LEN;
|
|
545
|
-
wasm.
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
397
|
+
const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
|
|
398
|
+
return ret === 0x100000001 ? undefined : ret;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
402
|
+
* to search, split or replace text in a string.
|
|
403
|
+
*
|
|
404
|
+
* If an invalid expression is given, then an error is returned.
|
|
405
|
+
* @param {string} re
|
|
406
|
+
*/
|
|
407
|
+
constructor(re) {
|
|
408
|
+
const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
409
|
+
const len0 = WASM_VECTOR_LEN;
|
|
410
|
+
const ret = wasm.rregex_new(ptr0, len0);
|
|
411
|
+
if (ret[2]) {
|
|
412
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
551
413
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
414
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
415
|
+
RRegexFinalization.register(this, this.__wbg_ptr, this);
|
|
416
|
+
return this;
|
|
555
417
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
* const re5 = new RRegex("[a&&b]")
|
|
584
|
-
* expect(re5.capturesLength()).toEqual(1)
|
|
585
|
-
* ```
|
|
586
|
-
*
|
|
587
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
588
|
-
* @returns {number}
|
|
589
|
-
*/
|
|
590
|
-
capturesLength() {
|
|
591
|
-
const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
|
|
592
|
-
return ret >>> 0;
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Replaces the leftmost-first match with the replacement provided.
|
|
596
|
-
* The replacement can be a regular string (where `$N` and `$name` are
|
|
597
|
-
* expanded to match capture groups) or a function that takes the matches'
|
|
598
|
-
* `Captures` and returns the replaced string.
|
|
599
|
-
*
|
|
600
|
-
* If no match is found, then a copy of the string is returned unchanged.
|
|
601
|
-
*
|
|
602
|
-
* # Replacement string syntax
|
|
603
|
-
*
|
|
604
|
-
* All instances of `$name` in the replacement text is replaced with the
|
|
605
|
-
* corresponding capture group `name`.
|
|
606
|
-
*
|
|
607
|
-
* `name` may be an integer corresponding to the index of the
|
|
608
|
-
* capture group (counted by order of opening parenthesis where `0` is the
|
|
609
|
-
* entire match) or it can be a name (consisting of letters, digits or
|
|
610
|
-
* underscores) corresponding to a named capture group.
|
|
611
|
-
*
|
|
612
|
-
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
613
|
-
* or isn't a valid index), then it is replaced with the empty string.
|
|
614
|
-
*
|
|
615
|
-
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
616
|
-
* group named `1a` and not the capture group at index `1`. To exert more
|
|
617
|
-
* precise control over the name, use braces, e.g., `${1}a`.
|
|
618
|
-
*
|
|
619
|
-
* To write a literal `$` use `$$`.
|
|
620
|
-
*
|
|
621
|
-
* # Examples
|
|
622
|
-
*
|
|
623
|
-
* Note that this function is polymorphic with respect to the replacement.
|
|
624
|
-
* In typical usage, this can just be a normal string:
|
|
625
|
-
*
|
|
626
|
-
* ```typescript
|
|
627
|
-
* import { RRegex } from "rregex"
|
|
628
|
-
*
|
|
629
|
-
* const re = new RRegex("[^01]+")
|
|
630
|
-
* expect(re.replace("1078910", "").toBe("1010")
|
|
631
|
-
* ```
|
|
632
|
-
*
|
|
633
|
-
* Here's the example using this expansion technique with named capture
|
|
634
|
-
* groups:
|
|
635
|
-
*
|
|
636
|
-
* ```typescript
|
|
637
|
-
* import { RRegex } from "rregex"
|
|
638
|
-
*
|
|
639
|
-
* const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
640
|
-
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
641
|
-
* expect(result).toBe("Bruce Springsteen")
|
|
642
|
-
* ```
|
|
643
|
-
*
|
|
644
|
-
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
645
|
-
* would produce the same result. To write a literal `$` use `$$`.
|
|
646
|
-
*
|
|
647
|
-
* Sometimes the replacement string requires use of curly braces to
|
|
648
|
-
* delineate a capture group replacement and surrounding literal text.
|
|
649
|
-
* For example, if we wanted to join two words together with an
|
|
650
|
-
* underscore:
|
|
651
|
-
*
|
|
652
|
-
* ```typescript
|
|
653
|
-
* import { RRegex } from "rregex"
|
|
654
|
-
*
|
|
655
|
-
* const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
656
|
-
* const result = re.replace("deep fried", "${first}_$second")
|
|
657
|
-
* expect(result).toBe("deep_fried")
|
|
658
|
-
* ```
|
|
659
|
-
*
|
|
660
|
-
* Without the curly braces, the capture group name `first_` would be
|
|
661
|
-
* used, and since it doesn't exist, it would be replaced with the empty
|
|
662
|
-
* string.
|
|
663
|
-
*
|
|
664
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
665
|
-
* @param {string} text - The string against which to match the regular expression
|
|
666
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
667
|
-
* @returns {string}
|
|
668
|
-
*/
|
|
669
|
-
replace(text, rep) {
|
|
670
|
-
let deferred3_0;
|
|
671
|
-
let deferred3_1;
|
|
672
|
-
try {
|
|
673
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
418
|
+
/**
|
|
419
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
420
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
421
|
+
*
|
|
422
|
+
* Note that this should only be used if you want to discover the position
|
|
423
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
424
|
+
* `isMatch`.
|
|
425
|
+
*
|
|
426
|
+
* # Example
|
|
427
|
+
*
|
|
428
|
+
* Find the start and end location of the first word with exactly 13
|
|
429
|
+
* Unicode word characters:
|
|
430
|
+
*
|
|
431
|
+
* ```typescript
|
|
432
|
+
* import { RRegex } from "rregex"
|
|
433
|
+
*
|
|
434
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
435
|
+
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
436
|
+
* expect(m.start).toBe(2)
|
|
437
|
+
* expect(m.end).toBe(15)
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
441
|
+
* @param {string} text - The string against which to match the regular expression
|
|
442
|
+
* @return {Match}
|
|
443
|
+
*/
|
|
444
|
+
find(text) {
|
|
674
445
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
675
446
|
const len0 = WASM_VECTOR_LEN;
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
deferred3_0 = r0;
|
|
682
|
-
deferred3_1 = r1;
|
|
683
|
-
return getStringFromWasm0(r0, r1);
|
|
684
|
-
} finally {
|
|
685
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
686
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
447
|
+
const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
|
|
448
|
+
if (ret[2]) {
|
|
449
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
450
|
+
}
|
|
451
|
+
return takeFromExternrefTable0(ret[0]);
|
|
687
452
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
453
|
+
/**
|
|
454
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
455
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
456
|
+
* text that *isn't* matched by the regular expression.
|
|
457
|
+
*
|
|
458
|
+
* This method will *not* copy the text given.
|
|
459
|
+
*
|
|
460
|
+
* # Example
|
|
461
|
+
*
|
|
462
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
463
|
+
*
|
|
464
|
+
* ```typescript
|
|
465
|
+
* import { RRegex } from "rregex"
|
|
466
|
+
*
|
|
467
|
+
* const re = new RRegex(r"[ \\t]+")
|
|
468
|
+
* const fields = re.split("a b \t c\td e")
|
|
469
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
473
|
+
* @param {string} text - The string against which to match the regular expression
|
|
474
|
+
* @returns {string[]}
|
|
475
|
+
*/
|
|
476
|
+
split(text) {
|
|
708
477
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
709
478
|
const len0 = WASM_VECTOR_LEN;
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
wasm.
|
|
713
|
-
|
|
714
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
715
|
-
deferred3_0 = r0;
|
|
716
|
-
deferred3_1 = r1;
|
|
717
|
-
return getStringFromWasm0(r0, r1);
|
|
718
|
-
} finally {
|
|
719
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
720
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
479
|
+
const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
|
|
480
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
481
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
482
|
+
return v2;
|
|
721
483
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
484
|
+
/**
|
|
485
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
486
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
487
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
488
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
489
|
+
* string that is not split will be the last element in the iterator.
|
|
490
|
+
*
|
|
491
|
+
* This method will *not* copy the text given.
|
|
492
|
+
*
|
|
493
|
+
* # Example
|
|
494
|
+
*
|
|
495
|
+
* Get the first two words in some text:
|
|
496
|
+
*
|
|
497
|
+
* ```typescript
|
|
498
|
+
* import { RRegex } from "rregex"
|
|
499
|
+
*
|
|
500
|
+
* const re = new RRegex(r"\\W+")
|
|
501
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
502
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
503
|
+
* ```
|
|
504
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
505
|
+
* @param {string} text - The string against which to match the regular expression
|
|
506
|
+
* @param {number} limit - Max number result elements
|
|
507
|
+
* @returns {string[]}
|
|
508
|
+
*/
|
|
509
|
+
splitn(text, limit) {
|
|
742
510
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
743
511
|
const len0 = WASM_VECTOR_LEN;
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
wasm.
|
|
747
|
-
|
|
748
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
749
|
-
deferred3_0 = r0;
|
|
750
|
-
deferred3_1 = r1;
|
|
751
|
-
return getStringFromWasm0(r0, r1);
|
|
752
|
-
} finally {
|
|
753
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
754
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
512
|
+
const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
|
|
513
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
514
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
515
|
+
return v2;
|
|
755
516
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
517
|
+
/**
|
|
518
|
+
* Returns the regular expression into a high level intermediate
|
|
519
|
+
* representation.
|
|
520
|
+
* @returns {any}
|
|
521
|
+
*/
|
|
522
|
+
syntax() {
|
|
523
|
+
const ret = wasm.rregex_syntax(this.__wbg_ptr);
|
|
524
|
+
if (ret[2]) {
|
|
525
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
526
|
+
}
|
|
527
|
+
return takeFromExternrefTable0(ret[0]);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Returns the same as find, but starts the search at the given
|
|
531
|
+
* offset.
|
|
532
|
+
*
|
|
533
|
+
* The significance of the starting point is that it takes the surrounding
|
|
534
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
535
|
+
* match when `start == 0`.
|
|
536
|
+
*
|
|
537
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
538
|
+
* @param {string} text - The string against which to match the regular expression
|
|
539
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
540
|
+
* @returns {Match}
|
|
541
|
+
*/
|
|
542
|
+
findAt(text, start) {
|
|
783
543
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
784
544
|
const len0 = WASM_VECTOR_LEN;
|
|
785
|
-
wasm.
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
return v2;
|
|
791
|
-
} finally {
|
|
792
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
545
|
+
const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
|
|
546
|
+
if (ret[2]) {
|
|
547
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
548
|
+
}
|
|
549
|
+
return takeFromExternrefTable0(ret[0]);
|
|
793
550
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
553
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
554
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
555
|
+
* `Captures` and returns the replaced string.
|
|
556
|
+
*
|
|
557
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
558
|
+
*
|
|
559
|
+
* # Replacement string syntax
|
|
560
|
+
*
|
|
561
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
562
|
+
* corresponding capture group `name`.
|
|
563
|
+
*
|
|
564
|
+
* `name` may be an integer corresponding to the index of the
|
|
565
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
566
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
567
|
+
* underscores) corresponding to a named capture group.
|
|
568
|
+
*
|
|
569
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
570
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
571
|
+
*
|
|
572
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
573
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
574
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
575
|
+
*
|
|
576
|
+
* To write a literal `$` use `$$`.
|
|
577
|
+
*
|
|
578
|
+
* # Examples
|
|
579
|
+
*
|
|
580
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
581
|
+
* In typical usage, this can just be a normal string:
|
|
582
|
+
*
|
|
583
|
+
* ```typescript
|
|
584
|
+
* import { RRegex } from "rregex"
|
|
585
|
+
*
|
|
586
|
+
* const re = new RRegex("[^01]+")
|
|
587
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* Here's the example using this expansion technique with named capture
|
|
591
|
+
* groups:
|
|
592
|
+
*
|
|
593
|
+
* ```typescript
|
|
594
|
+
* import { RRegex } from "rregex"
|
|
595
|
+
*
|
|
596
|
+
* const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
597
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
598
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
602
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
603
|
+
*
|
|
604
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
605
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
606
|
+
* For example, if we wanted to join two words together with an
|
|
607
|
+
* underscore:
|
|
608
|
+
*
|
|
609
|
+
* ```typescript
|
|
610
|
+
* import { RRegex } from "rregex"
|
|
611
|
+
*
|
|
612
|
+
* const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
613
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
614
|
+
* expect(result).toBe("deep_fried")
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
618
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
619
|
+
* string.
|
|
620
|
+
*
|
|
621
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
622
|
+
* @param {string} text - The string against which to match the regular expression
|
|
623
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
624
|
+
* @returns {string}
|
|
625
|
+
*/
|
|
626
|
+
replace(text, rep) {
|
|
627
|
+
let deferred3_0;
|
|
628
|
+
let deferred3_1;
|
|
629
|
+
try {
|
|
630
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
631
|
+
const len0 = WASM_VECTOR_LEN;
|
|
632
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
633
|
+
const len1 = WASM_VECTOR_LEN;
|
|
634
|
+
const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
635
|
+
deferred3_0 = ret[0];
|
|
636
|
+
deferred3_1 = ret[1];
|
|
637
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
638
|
+
} finally {
|
|
639
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
644
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
645
|
+
* match. If no match is found, then `undefined` is returned.
|
|
646
|
+
*
|
|
647
|
+
* You should only use `captures` if you need access to the location of
|
|
648
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
649
|
+
* the location of the overall match.
|
|
650
|
+
*
|
|
651
|
+
* # Examples
|
|
652
|
+
*
|
|
653
|
+
* Say you have some text with movie names and their release years,
|
|
654
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
655
|
+
* looking like that, while also extracting the movie name and its release
|
|
656
|
+
* year separately.
|
|
657
|
+
*
|
|
658
|
+
* ```typescript
|
|
659
|
+
* import { RRegex } from "rregex"
|
|
660
|
+
*
|
|
661
|
+
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
662
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
663
|
+
* const caps = re.captures(text)
|
|
664
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
665
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
666
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
670
|
+
* capture group is indexed by the order of its opening `(`.
|
|
671
|
+
*
|
|
672
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
673
|
+
*
|
|
674
|
+
* ```typescript
|
|
675
|
+
* import { RRegex } from "rregex"
|
|
676
|
+
*
|
|
677
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
678
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
679
|
+
* const caps = re.captures(text)
|
|
680
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
681
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
682
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
683
|
+
* ```
|
|
684
|
+
*
|
|
685
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
686
|
+
* @param {string} text - The string against which to match the regular expression
|
|
687
|
+
* @returns {Captures|undefined}
|
|
688
|
+
*/
|
|
689
|
+
captures(text) {
|
|
823
690
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
824
691
|
const len0 = WASM_VECTOR_LEN;
|
|
825
|
-
wasm.
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
return v2;
|
|
831
|
-
} finally {
|
|
832
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
692
|
+
const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
|
|
693
|
+
if (ret[2]) {
|
|
694
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
695
|
+
}
|
|
696
|
+
return takeFromExternrefTable0(ret[0]);
|
|
833
697
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
*
|
|
856
|
-
* ```typescript
|
|
857
|
-
* import { RRegex } from "rregex"
|
|
858
|
-
*
|
|
859
|
-
* const text = "aaaaa"
|
|
860
|
-
* const = new RRegex("a+").shortest_match(text)
|
|
861
|
-
* expect(pos).toBe(1)
|
|
862
|
-
* ```
|
|
863
|
-
*
|
|
864
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
865
|
-
* @param {string} text - The string against which to match the regular expression
|
|
866
|
-
* @returns {number|undefined}
|
|
867
|
-
*/
|
|
868
|
-
shortestMatch(text) {
|
|
869
|
-
try {
|
|
870
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
698
|
+
/**
|
|
699
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
700
|
+
* returning the start and end byte indices with respect to `text`.
|
|
701
|
+
*
|
|
702
|
+
* # Example
|
|
703
|
+
*
|
|
704
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
705
|
+
* word characters:
|
|
706
|
+
*
|
|
707
|
+
* ```typescript
|
|
708
|
+
* import { RRegex } from "rregex"
|
|
709
|
+
*
|
|
710
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
711
|
+
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
712
|
+
* ```
|
|
713
|
+
*
|
|
714
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
715
|
+
* @param {string} text - The string against which to match the regular expression
|
|
716
|
+
* @returns {Match}
|
|
717
|
+
*/
|
|
718
|
+
findAll(text) {
|
|
871
719
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
872
720
|
const len0 = WASM_VECTOR_LEN;
|
|
873
|
-
wasm.
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
721
|
+
const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
|
|
722
|
+
if (ret[2]) {
|
|
723
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
724
|
+
}
|
|
725
|
+
return takeFromExternrefTable0(ret[0]);
|
|
879
726
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
727
|
+
/**
|
|
728
|
+
* Returns true if and only if there is a match for the regex in the
|
|
729
|
+
* string given.
|
|
730
|
+
*
|
|
731
|
+
* It is recommended to use this method if all you need to do is test
|
|
732
|
+
* a match, since the underlying matching engine may be able to do less
|
|
733
|
+
* work.
|
|
734
|
+
*
|
|
735
|
+
* # Example
|
|
736
|
+
*
|
|
737
|
+
* Test if some text contains at least one word with exactly 13
|
|
738
|
+
* Unicode word characters:
|
|
739
|
+
*
|
|
740
|
+
* ```typescript
|
|
741
|
+
* import { RRegex } from "rregex"
|
|
742
|
+
*
|
|
743
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
744
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
748
|
+
* @param {string} text - The string against which to match the regular expression
|
|
749
|
+
* @return {boolean}
|
|
750
|
+
*/
|
|
751
|
+
isMatch(text) {
|
|
896
752
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
897
753
|
const len0 = WASM_VECTOR_LEN;
|
|
898
|
-
wasm.
|
|
899
|
-
|
|
900
|
-
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
901
|
-
return r0 === 0 ? undefined : r1 >>> 0;
|
|
902
|
-
} finally {
|
|
903
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
754
|
+
const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
|
|
755
|
+
return ret !== 0;
|
|
904
756
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
757
|
+
/**
|
|
758
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
759
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
760
|
+
* are replaced.
|
|
761
|
+
*
|
|
762
|
+
* See the documentation for `replace` for details on how to access
|
|
763
|
+
* capturing group matches in the replacement string.
|
|
764
|
+
*
|
|
765
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
766
|
+
* @param {string} text - The string against which to match the regular expression
|
|
767
|
+
* @param {number} limit - Max number of replacement
|
|
768
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
769
|
+
* @returns {string}
|
|
770
|
+
*/
|
|
771
|
+
replacen(text, limit, rep) {
|
|
772
|
+
let deferred3_0;
|
|
773
|
+
let deferred3_1;
|
|
774
|
+
try {
|
|
775
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
776
|
+
const len0 = WASM_VECTOR_LEN;
|
|
777
|
+
const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
778
|
+
const len1 = WASM_VECTOR_LEN;
|
|
779
|
+
const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
|
|
780
|
+
deferred3_0 = ret[0];
|
|
781
|
+
deferred3_1 = ret[1];
|
|
782
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
783
|
+
} finally {
|
|
784
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
920
785
|
}
|
|
921
|
-
return takeObject(r0);
|
|
922
|
-
} finally {
|
|
923
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
924
786
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
return getStringFromWasm0(r0, r1);
|
|
941
|
-
} finally {
|
|
942
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
943
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
787
|
+
/**
|
|
788
|
+
* Returns a string representing the regular expression
|
|
789
|
+
* @returns {string}
|
|
790
|
+
*/
|
|
791
|
+
toString() {
|
|
792
|
+
let deferred1_0;
|
|
793
|
+
let deferred1_1;
|
|
794
|
+
try {
|
|
795
|
+
const ret = wasm.rregex_toString(this.__wbg_ptr);
|
|
796
|
+
deferred1_0 = ret[0];
|
|
797
|
+
deferred1_1 = ret[1];
|
|
798
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
799
|
+
} finally {
|
|
800
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
801
|
+
}
|
|
944
802
|
}
|
|
945
803
|
}
|
|
946
|
-
|
|
947
|
-
__exports.RRegex = RRegex;
|
|
948
|
-
|
|
949
|
-
const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
950
|
-
? { register: () => {}, unregister: () => {} }
|
|
951
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0));
|
|
952
|
-
/**
|
|
953
|
-
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
954
|
-
* A regex set corresponds to the union of two or more regular expressions.
|
|
955
|
-
*
|
|
956
|
-
* That is, a regex set will match text where at least one of its constituent
|
|
957
|
-
* regular expressions matches. A regex set as its formulated here provides a
|
|
958
|
-
* touch more power: it will also report which regular expressions in the set match.
|
|
959
|
-
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
960
|
-
* with many alternates, since only one alternate can match at a time.
|
|
961
|
-
*
|
|
962
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
963
|
-
*/
|
|
964
|
-
class RRegexSet {
|
|
965
|
-
|
|
966
|
-
__destroy_into_raw() {
|
|
967
|
-
const ptr = this.__wbg_ptr;
|
|
968
|
-
this.__wbg_ptr = 0;
|
|
969
|
-
RRegexSetFinalization.unregister(this);
|
|
970
|
-
return ptr;
|
|
971
|
-
}
|
|
804
|
+
__exports.RRegex = RRegex;
|
|
972
805
|
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
wasm.__wbg_rregexset_free(ptr);
|
|
976
|
-
}
|
|
806
|
+
const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
807
|
+
? { register: () => {}, unregister: () => {} }
|
|
808
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0, 1));
|
|
977
809
|
/**
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
810
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
811
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
812
|
+
*
|
|
813
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
814
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
815
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
816
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
817
|
+
* with many alternates, since only one alternate can match at a time.
|
|
818
|
+
*
|
|
819
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
820
|
+
*/
|
|
821
|
+
class RRegexSet {
|
|
822
|
+
|
|
823
|
+
__destroy_into_raw() {
|
|
824
|
+
const ptr = this.__wbg_ptr;
|
|
825
|
+
this.__wbg_ptr = 0;
|
|
826
|
+
RRegexSetFinalization.unregister(this);
|
|
827
|
+
return ptr;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
free() {
|
|
831
|
+
const ptr = this.__destroy_into_raw();
|
|
832
|
+
wasm.__wbg_rregexset_free(ptr, 0);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Create a new regex set with the given regular expressions.
|
|
836
|
+
*
|
|
837
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
838
|
+
* expressions, then an error is returned.
|
|
839
|
+
*
|
|
840
|
+
* # Example
|
|
841
|
+
*
|
|
842
|
+
* Create a new regex set from an iterator of strings:
|
|
843
|
+
*
|
|
844
|
+
* ```typescript
|
|
845
|
+
* import { RegexSet } from "rregex"
|
|
846
|
+
*
|
|
847
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
848
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
849
|
+
* ```
|
|
850
|
+
* @param {Array<any>} list
|
|
851
|
+
*/
|
|
852
|
+
constructor(list) {
|
|
853
|
+
const ret = wasm.rregexset_new(list);
|
|
854
|
+
if (ret[2]) {
|
|
855
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1004
856
|
}
|
|
1005
|
-
this.__wbg_ptr =
|
|
857
|
+
this.__wbg_ptr = ret[0] >>> 0;
|
|
858
|
+
RRegexSetFinalization.register(this, this.__wbg_ptr, this);
|
|
1006
859
|
return this;
|
|
1007
|
-
} finally {
|
|
1008
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1009
|
-
heap[stack_pointer++] = undefined;
|
|
1010
860
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
* Returns the set of regular expressions that match in the given text.
|
|
1051
|
-
*
|
|
1052
|
-
* The set returned contains the index of each regular expression that
|
|
1053
|
-
* matches in the given text. The index is in correspondence with the
|
|
1054
|
-
* order of regular expressions given to `RegexSet`'s constructor.
|
|
1055
|
-
*
|
|
1056
|
-
* The set can also be used to iterate over the matched indices.
|
|
1057
|
-
*
|
|
1058
|
-
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1059
|
-
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1060
|
-
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1061
|
-
* text.
|
|
1062
|
-
*
|
|
1063
|
-
* # Example
|
|
1064
|
-
*
|
|
1065
|
-
* Tests which regular expressions match the given text:
|
|
1066
|
-
*
|
|
1067
|
-
* ```typescript
|
|
1068
|
-
* import { RegexSet } from "rregex"
|
|
1069
|
-
*
|
|
1070
|
-
* const set = new RegexSet([
|
|
1071
|
-
* "\\w+",
|
|
1072
|
-
* "\\d+",
|
|
1073
|
-
* "\\pL+",
|
|
1074
|
-
* "foo",
|
|
1075
|
-
* "bar",
|
|
1076
|
-
* "barfoo",
|
|
1077
|
-
* "foobar",
|
|
1078
|
-
* ])
|
|
1079
|
-
* const matches = set.matches("foobar")
|
|
1080
|
-
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
1081
|
-
* ```
|
|
1082
|
-
*
|
|
1083
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1084
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1085
|
-
* @return {number[]}
|
|
1086
|
-
*/
|
|
1087
|
-
matches(text) {
|
|
1088
|
-
try {
|
|
1089
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
861
|
+
/**
|
|
862
|
+
* Returns the set of regular expressions that match in the given text.
|
|
863
|
+
*
|
|
864
|
+
* The set returned contains the index of each regular expression that
|
|
865
|
+
* matches in the given text. The index is in correspondence with the
|
|
866
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
867
|
+
*
|
|
868
|
+
* The set can also be used to iterate over the matched indices.
|
|
869
|
+
*
|
|
870
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
871
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
872
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
873
|
+
* text.
|
|
874
|
+
*
|
|
875
|
+
* # Example
|
|
876
|
+
*
|
|
877
|
+
* Tests which regular expressions match the given text:
|
|
878
|
+
*
|
|
879
|
+
* ```typescript
|
|
880
|
+
* import { RegexSet } from "rregex"
|
|
881
|
+
*
|
|
882
|
+
* const set = new RegexSet([
|
|
883
|
+
* "\\w+",
|
|
884
|
+
* "\\d+",
|
|
885
|
+
* "\\pL+",
|
|
886
|
+
* "foo",
|
|
887
|
+
* "bar",
|
|
888
|
+
* "barfoo",
|
|
889
|
+
* "foobar",
|
|
890
|
+
* ])
|
|
891
|
+
* const matches = set.matches("foobar")
|
|
892
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
893
|
+
* ```
|
|
894
|
+
*
|
|
895
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
896
|
+
* @param {string} text - The string against which to match the regular expression
|
|
897
|
+
* @return {number[]}
|
|
898
|
+
*/
|
|
899
|
+
matches(text) {
|
|
1090
900
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1091
901
|
const len0 = WASM_VECTOR_LEN;
|
|
1092
|
-
wasm.rregexset_matches(
|
|
1093
|
-
var
|
|
1094
|
-
|
|
1095
|
-
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
1096
|
-
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
902
|
+
const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
|
|
903
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
904
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
1097
905
|
return v2;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
909
|
+
* the text given.
|
|
910
|
+
*
|
|
911
|
+
* This method should be preferred if you only need to test whether any
|
|
912
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
913
|
+
* regexes matched. This is because the underlying matching engine will
|
|
914
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
915
|
+
* find all matches.
|
|
916
|
+
*
|
|
917
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
918
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
919
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
920
|
+
* text.
|
|
921
|
+
*
|
|
922
|
+
* # Example
|
|
923
|
+
*
|
|
924
|
+
* Tests whether a set matches some text:
|
|
925
|
+
*
|
|
926
|
+
* ```typescript
|
|
927
|
+
* import { RegexSet } from "rregex"
|
|
928
|
+
*
|
|
929
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
930
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
931
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
932
|
+
* ```
|
|
933
|
+
*
|
|
934
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
935
|
+
* @param {string} text - The string against which to match the regular expression
|
|
936
|
+
* @return {boolean}
|
|
937
|
+
*/
|
|
938
|
+
isMatch(text) {
|
|
939
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
940
|
+
const len0 = WASM_VECTOR_LEN;
|
|
941
|
+
const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
|
|
942
|
+
return ret !== 0;
|
|
1100
943
|
}
|
|
1101
944
|
}
|
|
1102
|
-
|
|
1103
|
-
__exports.RRegexSet = RRegexSet;
|
|
945
|
+
__exports.RRegexSet = RRegexSet;
|
|
1104
946
|
|
|
1105
|
-
async function __wbg_load(module, imports) {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
947
|
+
async function __wbg_load(module, imports) {
|
|
948
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
949
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
950
|
+
try {
|
|
951
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
1110
952
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
953
|
+
} catch (e) {
|
|
954
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
955
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
1114
956
|
|
|
1115
|
-
|
|
1116
|
-
|
|
957
|
+
} else {
|
|
958
|
+
throw e;
|
|
959
|
+
}
|
|
1117
960
|
}
|
|
1118
961
|
}
|
|
1119
|
-
}
|
|
1120
962
|
|
|
1121
|
-
|
|
1122
|
-
|
|
963
|
+
const bytes = await module.arrayBuffer();
|
|
964
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1123
965
|
|
|
1124
|
-
|
|
1125
|
-
|
|
966
|
+
} else {
|
|
967
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
1126
968
|
|
|
1127
|
-
|
|
1128
|
-
|
|
969
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
970
|
+
return { instance, module };
|
|
1129
971
|
|
|
1130
|
-
|
|
1131
|
-
|
|
972
|
+
} else {
|
|
973
|
+
return instance;
|
|
974
|
+
}
|
|
1132
975
|
}
|
|
1133
976
|
}
|
|
1134
|
-
}
|
|
1135
977
|
|
|
1136
|
-
function __wbg_get_imports() {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
978
|
+
function __wbg_get_imports() {
|
|
979
|
+
const imports = {};
|
|
980
|
+
imports.wbg = {};
|
|
981
|
+
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
982
|
+
const ret = arg0.buffer;
|
|
983
|
+
return ret;
|
|
984
|
+
};
|
|
985
|
+
imports.wbg.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
|
|
986
|
+
const ret = String.fromCodePoint(arg0 >>> 0);
|
|
987
|
+
return ret;
|
|
988
|
+
}, arguments) };
|
|
989
|
+
imports.wbg.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
|
|
990
|
+
const ret = Array.from(arg0);
|
|
991
|
+
return ret;
|
|
992
|
+
};
|
|
993
|
+
imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
|
|
994
|
+
const ret = arg0[arg1 >>> 0];
|
|
995
|
+
return ret;
|
|
996
|
+
};
|
|
997
|
+
imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
|
|
998
|
+
const ret = arg0.length;
|
|
999
|
+
return ret;
|
|
1000
|
+
};
|
|
1001
|
+
imports.wbg.__wbg_new_405e22f390576ce2 = function() {
|
|
1002
|
+
const ret = new Object();
|
|
1003
|
+
return ret;
|
|
1004
|
+
};
|
|
1005
|
+
imports.wbg.__wbg_new_78feb108b6472713 = function() {
|
|
1006
|
+
const ret = new Array();
|
|
1007
|
+
return ret;
|
|
1008
|
+
};
|
|
1009
|
+
imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
|
|
1010
|
+
const ret = new Uint8Array(arg0);
|
|
1011
|
+
return ret;
|
|
1012
|
+
};
|
|
1013
|
+
imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
|
1014
|
+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
1015
|
+
return ret;
|
|
1016
|
+
};
|
|
1017
|
+
imports.wbg.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
|
|
1018
|
+
const ret = arg0.push(arg1);
|
|
1019
|
+
return ret;
|
|
1020
|
+
};
|
|
1021
|
+
imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
|
|
1022
|
+
arg0[arg1 >>> 0] = arg2;
|
|
1023
|
+
};
|
|
1024
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
1025
|
+
arg0[arg1] = arg2;
|
|
1026
|
+
};
|
|
1027
|
+
imports.wbg.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
1028
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
1029
|
+
return ret;
|
|
1030
|
+
}, arguments) };
|
|
1031
|
+
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
1032
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
1033
|
+
return ret;
|
|
1034
|
+
};
|
|
1035
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
1036
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1037
|
+
return ret;
|
|
1038
|
+
};
|
|
1039
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
1040
|
+
const table = wasm.__wbindgen_export_2;
|
|
1041
|
+
const offset = table.grow(4);
|
|
1042
|
+
table.set(0, undefined);
|
|
1043
|
+
table.set(offset + 0, undefined);
|
|
1044
|
+
table.set(offset + 1, null);
|
|
1045
|
+
table.set(offset + 2, true);
|
|
1046
|
+
table.set(offset + 3, false);
|
|
1047
|
+
;
|
|
1048
|
+
};
|
|
1049
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
1050
|
+
const ret = wasm.memory;
|
|
1051
|
+
return ret;
|
|
1052
|
+
};
|
|
1053
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
1054
|
+
const ret = arg0;
|
|
1055
|
+
return ret;
|
|
1056
|
+
};
|
|
1057
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
1058
|
+
const obj = arg1;
|
|
1059
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
1060
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1061
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1062
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1063
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1064
|
+
};
|
|
1065
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
1066
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
1067
|
+
return ret;
|
|
1068
|
+
};
|
|
1069
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
1070
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
return imports;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
function __wbg_init_memory(imports, memory) {
|
|
1077
|
+
|
|
1078
|
+
}
|
|
1227
1079
|
|
|
1228
|
-
|
|
1229
|
-
|
|
1080
|
+
function __wbg_finalize_init(instance, module) {
|
|
1081
|
+
wasm = instance.exports;
|
|
1082
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
1083
|
+
cachedDataViewMemory0 = null;
|
|
1084
|
+
cachedUint8ArrayMemory0 = null;
|
|
1230
1085
|
|
|
1231
|
-
function __wbg_init_memory(imports, maybe_memory) {
|
|
1232
1086
|
|
|
1233
|
-
|
|
1087
|
+
wasm.__wbindgen_start();
|
|
1088
|
+
return wasm;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function initSync(module) {
|
|
1092
|
+
if (wasm !== undefined) return wasm;
|
|
1234
1093
|
|
|
1235
|
-
function __wbg_finalize_init(instance, module) {
|
|
1236
|
-
wasm = instance.exports;
|
|
1237
|
-
__wbg_init.__wbindgen_wasm_module = module;
|
|
1238
|
-
cachedInt32Memory0 = null;
|
|
1239
|
-
cachedUint32Memory0 = null;
|
|
1240
|
-
cachedUint8Memory0 = null;
|
|
1241
1094
|
|
|
1095
|
+
if (typeof module !== 'undefined') {
|
|
1096
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1097
|
+
({module} = module)
|
|
1098
|
+
} else {
|
|
1099
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1242
1102
|
|
|
1243
|
-
|
|
1244
|
-
}
|
|
1103
|
+
const imports = __wbg_get_imports();
|
|
1245
1104
|
|
|
1246
|
-
|
|
1247
|
-
if (wasm !== undefined) return wasm;
|
|
1105
|
+
__wbg_init_memory(imports);
|
|
1248
1106
|
|
|
1249
|
-
|
|
1107
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
1108
|
+
module = new WebAssembly.Module(module);
|
|
1109
|
+
}
|
|
1250
1110
|
|
|
1251
|
-
|
|
1111
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
1252
1112
|
|
|
1253
|
-
|
|
1254
|
-
module = new WebAssembly.Module(module);
|
|
1113
|
+
return __wbg_finalize_init(instance, module);
|
|
1255
1114
|
}
|
|
1256
1115
|
|
|
1257
|
-
|
|
1116
|
+
async function __wbg_init(module_or_path) {
|
|
1117
|
+
if (wasm !== undefined) return wasm;
|
|
1258
1118
|
|
|
1259
|
-
return __wbg_finalize_init(instance, module);
|
|
1260
|
-
}
|
|
1261
1119
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1120
|
+
if (typeof module_or_path !== 'undefined') {
|
|
1121
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1122
|
+
({module_or_path} = module_or_path)
|
|
1123
|
+
} else {
|
|
1124
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1264
1127
|
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1128
|
+
if (typeof module_or_path === 'undefined' && typeof script_src !== 'undefined') {
|
|
1129
|
+
module_or_path = script_src.replace(/standalone\.js$/, 'rregex.wasm');
|
|
1130
|
+
}
|
|
1131
|
+
const imports = __wbg_get_imports();
|
|
1269
1132
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1133
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1134
|
+
module_or_path = fetch(module_or_path);
|
|
1135
|
+
}
|
|
1273
1136
|
|
|
1274
|
-
|
|
1137
|
+
__wbg_init_memory(imports);
|
|
1275
1138
|
|
|
1276
|
-
|
|
1139
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1277
1140
|
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1141
|
+
return __wbg_finalize_init(instance, module);
|
|
1142
|
+
}
|
|
1280
1143
|
|
|
1281
|
-
wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
|
|
1144
|
+
wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports);
|
|
1282
1145
|
|
|
1283
1146
|
})();
|