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