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