| 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 { ICU4XLineBreakIteratorLatin1 } from "./ICU4XLineBreakIteratorLatin1.mjs" |
| 5 |
import { ICU4XLineBreakIteratorUtf16 } from "./ICU4XLineBreakIteratorUtf16.mjs" |
| 6 |
import { ICU4XLineBreakIteratorUtf8 } from "./ICU4XLineBreakIteratorUtf8.mjs" |
| 7 |
import { ICU4XLineBreakStrictness_js_to_rust, ICU4XLineBreakStrictness_rust_to_js } from "./ICU4XLineBreakStrictness.mjs" |
| 8 |
import { ICU4XLineBreakWordOption_js_to_rust, ICU4XLineBreakWordOption_rust_to_js } from "./ICU4XLineBreakWordOption.mjs" |
| 9 |
|
| 10 |
const ICU4XLineSegmenter_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 11 |
wasm.ICU4XLineSegmenter_destroy(underlying); |
| 12 |
}); |
| 13 |
|
| 14 |
export class ICU4XLineSegmenter { |
| 15 |
#lifetimeEdges = []; |
| 16 |
constructor(underlying, owned, edges) { |
| 17 |
this.underlying = underlying; |
| 18 |
this.#lifetimeEdges.push(...edges); |
| 19 |
if (owned) { |
| 20 |
ICU4XLineSegmenter_box_destroy_registry.register(this, underlying); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
static create_auto(arg_provider) { |
| 25 |
return (() => { |
| 26 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 27 |
wasm.ICU4XLineSegmenter_create_auto(diplomat_receive_buffer, arg_provider.underlying); |
| 28 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 29 |
if (is_ok) { |
| 30 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 31 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 32 |
return ok_value; |
| 33 |
} else { |
| 34 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 35 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 36 |
throw new diplomatRuntime.FFIError(throw_value); |
| 37 |
} |
| 38 |
})(); |
| 39 |
} |
| 40 |
|
| 41 |
static create_lstm(arg_provider) { |
| 42 |
return (() => { |
| 43 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 44 |
wasm.ICU4XLineSegmenter_create_lstm(diplomat_receive_buffer, arg_provider.underlying); |
| 45 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 46 |
if (is_ok) { |
| 47 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 48 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 49 |
return ok_value; |
| 50 |
} else { |
| 51 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 52 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 53 |
throw new diplomatRuntime.FFIError(throw_value); |
| 54 |
} |
| 55 |
})(); |
| 56 |
} |
| 57 |
|
| 58 |
static create_dictionary(arg_provider) { |
| 59 |
return (() => { |
| 60 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 61 |
wasm.ICU4XLineSegmenter_create_dictionary(diplomat_receive_buffer, arg_provider.underlying); |
| 62 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 63 |
if (is_ok) { |
| 64 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 65 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 66 |
return ok_value; |
| 67 |
} else { |
| 68 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 69 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 70 |
throw new diplomatRuntime.FFIError(throw_value); |
| 71 |
} |
| 72 |
})(); |
| 73 |
} |
| 74 |
|
| 75 |
static create_auto_with_options_v1(arg_provider, arg_options) { |
| 76 |
const field_strictness_arg_options = arg_options["strictness"]; |
| 77 |
const field_word_option_arg_options = arg_options["word_option"]; |
| 78 |
const field_ja_zh_arg_options = arg_options["ja_zh"]; |
| 79 |
return (() => { |
| 80 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 81 |
wasm.ICU4XLineSegmenter_create_auto_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, ICU4XLineBreakStrictness_js_to_rust[field_strictness_arg_options], ICU4XLineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); |
| 82 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 83 |
if (is_ok) { |
| 84 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 85 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 86 |
return ok_value; |
| 87 |
} else { |
| 88 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 89 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 90 |
throw new diplomatRuntime.FFIError(throw_value); |
| 91 |
} |
| 92 |
})(); |
| 93 |
} |
| 94 |
|
| 95 |
static create_lstm_with_options_v1(arg_provider, arg_options) { |
| 96 |
const field_strictness_arg_options = arg_options["strictness"]; |
| 97 |
const field_word_option_arg_options = arg_options["word_option"]; |
| 98 |
const field_ja_zh_arg_options = arg_options["ja_zh"]; |
| 99 |
return (() => { |
| 100 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 101 |
wasm.ICU4XLineSegmenter_create_lstm_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, ICU4XLineBreakStrictness_js_to_rust[field_strictness_arg_options], ICU4XLineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); |
| 102 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 103 |
if (is_ok) { |
| 104 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 105 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 106 |
return ok_value; |
| 107 |
} else { |
| 108 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 109 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 110 |
throw new diplomatRuntime.FFIError(throw_value); |
| 111 |
} |
| 112 |
})(); |
| 113 |
} |
| 114 |
|
| 115 |
static create_dictionary_with_options_v1(arg_provider, arg_options) { |
| 116 |
const field_strictness_arg_options = arg_options["strictness"]; |
| 117 |
const field_word_option_arg_options = arg_options["word_option"]; |
| 118 |
const field_ja_zh_arg_options = arg_options["ja_zh"]; |
| 119 |
return (() => { |
| 120 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 121 |
wasm.ICU4XLineSegmenter_create_dictionary_with_options_v1(diplomat_receive_buffer, arg_provider.underlying, ICU4XLineBreakStrictness_js_to_rust[field_strictness_arg_options], ICU4XLineBreakWordOption_js_to_rust[field_word_option_arg_options], field_ja_zh_arg_options); |
| 122 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 123 |
if (is_ok) { |
| 124 |
const ok_value = new ICU4XLineSegmenter(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 125 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 126 |
return ok_value; |
| 127 |
} else { |
| 128 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 129 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 130 |
throw new diplomatRuntime.FFIError(throw_value); |
| 131 |
} |
| 132 |
})(); |
| 133 |
} |
| 134 |
|
| 135 |
segment_utf8(arg_input) { |
| 136 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); |
| 137 |
const diplomat_out = new ICU4XLineBreakIteratorUtf8(wasm.ICU4XLineSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 138 |
buf_arg_input.garbageCollect(); |
| 139 |
return diplomat_out; |
| 140 |
} |
| 141 |
|
| 142 |
segment_utf16(arg_input) { |
| 143 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input); |
| 144 |
const diplomat_out = new ICU4XLineBreakIteratorUtf16(wasm.ICU4XLineSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 145 |
buf_arg_input.garbageCollect(); |
| 146 |
return diplomat_out; |
| 147 |
} |
| 148 |
|
| 149 |
segment_latin1(arg_input) { |
| 150 |
const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, "u8"); |
| 151 |
const diplomat_out = new ICU4XLineBreakIteratorLatin1(wasm.ICU4XLineSegmenter_segment_latin1(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); |
| 152 |
buf_arg_input.garbageCollect(); |
| 153 |
return diplomat_out; |
| 154 |
} |
| 155 |
} |