| 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 { ICU4XGraphemeClusterBreakIteratorLatin1 } from "./ICU4XGraphemeClusterBreakIteratorLatin1.mjs" |
| 5 |
import { ICU4XGraphemeClusterBreakIteratorUtf16 } from "./ICU4XGraphemeClusterBreakIteratorUtf16.mjs" |
| 6 |
import { ICU4XGraphemeClusterBreakIteratorUtf8 } from "./ICU4XGraphemeClusterBreakIteratorUtf8.mjs" |
| 7 |
|
| 8 |
const ICU4XGraphemeClusterSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 9 |
wasm.ICU4XGraphemeClusterSegmenter_destroy(underlying); |
| 10 |
}); |
| 11 |
|
| 12 |
export class ICU4XGraphemeClusterSegmenter { |
| 13 |
#lifetimeEdges = []; |
| 14 |
constructor(underlying, owned, edges) { |
| 15 |
this.underlying = underlying; |
| 16 |
this.#lifetimeEdges.push(...edges); |
| 17 |
if (owned) { |
| 18 |
ICU4XGraphemeClusterSegmenter_box_destroy_registry.register(this, underlying); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
static create(arg_provider) { |
| 23 |
return (() => { |
| 24 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 25 |
wasm.ICU4XGraphemeClusterSegmenter_create(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 ICU4XGraphemeClusterSegmenter(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 |
segment_utf8(arg_input) { |
| 40 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); |
| 41 |
const diplomat_out = new ICU4XGraphemeClusterBreakIteratorUtf8(wasm.ICU4XGraphemeClusterSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 42 |
buf_arg_input.garbageCollect(); |
| 43 |
return diplomat_out; |
| 44 |
} |
| 45 |
|
| 46 |
segment_utf16(arg_input) { |
| 47 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); |
| 48 |
const diplomat_out = new ICU4XGraphemeClusterBreakIteratorUtf16(wasm.ICU4XGraphemeClusterSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 49 |
buf_arg_input.garbageCollect(); |
| 50 |
return diplomat_out; |
| 51 |
} |
| 52 |
|
| 53 |
segment_latin1(arg_input) { |
| 54 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); |
| 55 |
const diplomat_out = new ICU4XGraphemeClusterBreakIteratorLatin1(wasm.ICU4XGraphemeClusterSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 56 |
buf_arg_input.garbageCollect(); |
| 57 |
return diplomat_out; |
| 58 |
} |
| 59 |
} |