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