| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 4 |
import { ICU4XWordBreakIteratorLatin1 } from "./ICU4XWordBreakIteratorLatin1.mjs" |
| 5 |
import { ICU4XWordBreakIteratorUtf16 } from "./ICU4XWordBreakIteratorUtf16.mjs" |
| 6 |
import { ICU4XWordBreakIteratorUtf8 } from "./ICU4XWordBreakIteratorUtf8.mjs" |
| 7 |
|
| 8 |
const ICU4XWordSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 9 |
wasm.ICU4XWordSegmenter_destroy(underlying); |
| 10 |
}); |
| 11 |
|
| 12 |
export class ICU4XWordSegmenter { |
| 13 |
#lifetimeEdges = []; |
| 14 |
constructor(underlying, owned, edges) { |
| 15 |
this.underlying = underlying; |
| 16 |
this.#lifetimeEdges.push(...edges); |
| 17 |
if (owned) { |
| 18 |
ICU4XWordSegmenter_box_destroy_registry.register(this, underlying); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
static create_auto(arg_provider) { |
| 23 |
return (() => { |
| 24 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 25 |
wasm.ICU4XWordSegmenter_create_auto(diplomat_receive_buffer, arg_provider.underlying); |
| 26 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 27 |
if (is_ok) { |
| 28 |
const ok_value = new ICU4XWordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 29 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 30 |
return ok_value; |
| 31 |
} else { |
| 32 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 33 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 34 |
throw new diplomatRuntime.FFIError(throw_value); |
| 35 |
} |
| 36 |
})(); |
| 37 |
} |
| 38 |
|
| 39 |
static create_lstm(arg_provider) { |
| 40 |
return (() => { |
| 41 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 42 |
wasm.ICU4XWordSegmenter_create_lstm(diplomat_receive_buffer, arg_provider.underlying); |
| 43 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 44 |
if (is_ok) { |
| 45 |
const ok_value = new ICU4XWordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 46 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 47 |
return ok_value; |
| 48 |
} else { |
| 49 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 50 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 51 |
throw new diplomatRuntime.FFIError(throw_value); |
| 52 |
} |
| 53 |
})(); |
| 54 |
} |
| 55 |
|
| 56 |
static create_dictionary(arg_provider) { |
| 57 |
return (() => { |
| 58 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 59 |
wasm.ICU4XWordSegmenter_create_dictionary(diplomat_receive_buffer, arg_provider.underlying); |
| 60 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 61 |
if (is_ok) { |
| 62 |
const ok_value = new ICU4XWordSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 63 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 64 |
return ok_value; |
| 65 |
} else { |
| 66 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 67 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 68 |
throw new diplomatRuntime.FFIError(throw_value); |
| 69 |
} |
| 70 |
})(); |
| 71 |
} |
| 72 |
|
| 73 |
segment_utf8(arg_input) { |
| 74 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); |
| 75 |
const diplomat_out = new ICU4XWordBreakIteratorUtf8(wasm.ICU4XWordSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 76 |
buf_arg_input.garbageCollect(); |
| 77 |
return diplomat_out; |
| 78 |
} |
| 79 |
|
| 80 |
segment_utf16(arg_input) { |
| 81 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); |
| 82 |
const diplomat_out = new ICU4XWordBreakIteratorUtf16(wasm.ICU4XWordSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 83 |
buf_arg_input.garbageCollect(); |
| 84 |
return diplomat_out; |
| 85 |
} |
| 86 |
|
| 87 |
segment_latin1(arg_input) { |
| 88 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); |
| 89 |
const diplomat_out = new ICU4XWordBreakIteratorLatin1(wasm.ICU4XWordSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 90 |
buf_arg_input.garbageCollect(); |
| 91 |
return diplomat_out; |
| 92 |
} |
| 93 |
} |