-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.html
52 lines (45 loc) · 1.1 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Rust WASM Regex Example</title>
<script type="module">
import init, { count_regex_matches } from './pkg/wasm_regex.js';
async function main() {
await init();
const strings = [
"Washington",
"Adams",
"Jefferson",
"Madison",
"Monroe",
"Adams",
"Jackson",
"Van Buren",
"Harrison",
"Tyler",
"Polk",
"Taylor",
"Fillmore",
"Pierce",
"Buchanan",
];
const vector = new TextEncoder().encode(strings.join(''));
const offsets = [0];
for (let i = 0; i < strings.length; i++) {
offsets.push(offsets[i] + strings[i].length);
}
const regex = "a";
const result = count_regex_matches(vector, offsets, regex);
const matches = new Float32Array(result);
for (let president of strings) {
console.log(president, matches[strings.indexOf(president)])
}
}
main();
</script>
</head>
<body>
<h1>Rust WASM Regex Example</h1>
</body>
</html>