Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XTitlecaseMapper.mjs

raw
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 { ICU4XLeadingAdjustment_js_to_rust, ICU4XLeadingAdjustment_rust_to_js } from "./ICU4XLeadingAdjustment.mjs"
5 import { ICU4XTrailingCase_js_to_rust, ICU4XTrailingCase_rust_to_js } from "./ICU4XTrailingCase.mjs"
6
7 const ICU4XTitlecaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XTitlecaseMapper_destroy(underlying);
9 });
10
11 export class ICU4XTitlecaseMapper {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XTitlecaseMapper_box_destroy_registry.register(this, underlying);
18 }
19 }
20
21 static create(arg_provider) {
22 return (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XTitlecaseMapper_create(diplomat_receive_buffer, arg_provider.underlying);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XTitlecaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
28 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
29 return ok_value;
30 } else {
31 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
32 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
33 throw new diplomatRuntime.FFIError(throw_value);
34 }
35 })();
36 }
37
38 titlecase_segment_v1(arg_s, arg_locale, arg_options) {
39 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
40 const field_leading_adjustment_arg_options = arg_options["leading_adjustment"];
41 const field_trailing_case_arg_options = arg_options["trailing_case"];
42 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
43 return (() => {
44 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
45 wasm.ICU4XTitlecaseMapper_titlecase_segment_v1(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, ICU4XLeadingAdjustment_js_to_rust[field_leading_adjustment_arg_options], ICU4XTrailingCase_js_to_rust[field_trailing_case_arg_options], writeable);
46 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
47 if (is_ok) {
48 const ok_value = {};
49 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
50 return ok_value;
51 } else {
52 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
53 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
54 throw new diplomatRuntime.FFIError(throw_value);
55 }
56 })();
57 });
58 buf_arg_s.free();
59 return diplomat_out;
60 }
61 }