Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XCaseMapper.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 ICU4XCaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XCaseMapper_destroy(underlying);
9 });
10
11 export class ICU4XCaseMapper {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XCaseMapper_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.ICU4XCaseMapper_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 ICU4XCaseMapper(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 lowercase(arg_s, arg_locale) {
39 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
40 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
41 return (() => {
42 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
43 wasm.ICU4XCaseMapper_lowercase(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, writeable);
44 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
45 if (is_ok) {
46 const ok_value = {};
47 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
48 return ok_value;
49 } else {
50 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
51 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
52 throw new diplomatRuntime.FFIError(throw_value);
53 }
54 })();
55 });
56 buf_arg_s.free();
57 return diplomat_out;
58 }
59
60 uppercase(arg_s, arg_locale) {
61 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
62 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
63 return (() => {
64 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
65 wasm.ICU4XCaseMapper_uppercase(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, writeable);
66 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
67 if (is_ok) {
68 const ok_value = {};
69 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
70 return ok_value;
71 } else {
72 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
73 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
74 throw new diplomatRuntime.FFIError(throw_value);
75 }
76 })();
77 });
78 buf_arg_s.free();
79 return diplomat_out;
80 }
81
82 titlecase_segment_with_only_case_data_v1(arg_s, arg_locale, arg_options) {
83 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
84 const field_leading_adjustment_arg_options = arg_options["leading_adjustment"];
85 const field_trailing_case_arg_options = arg_options["trailing_case"];
86 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
87 return (() => {
88 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
89 wasm.ICU4XCaseMapper_titlecase_segment_with_only_case_data_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);
90 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
91 if (is_ok) {
92 const ok_value = {};
93 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
94 return ok_value;
95 } else {
96 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
97 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
98 throw new diplomatRuntime.FFIError(throw_value);
99 }
100 })();
101 });
102 buf_arg_s.free();
103 return diplomat_out;
104 }
105
106 fold(arg_s) {
107 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
108 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
109 return (() => {
110 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
111 wasm.ICU4XCaseMapper_fold(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, writeable);
112 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
113 if (is_ok) {
114 const ok_value = {};
115 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
116 return ok_value;
117 } else {
118 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
119 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
120 throw new diplomatRuntime.FFIError(throw_value);
121 }
122 })();
123 });
124 buf_arg_s.free();
125 return diplomat_out;
126 }
127
128 fold_turkic(arg_s) {
129 const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s);
130 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
131 return (() => {
132 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
133 wasm.ICU4XCaseMapper_fold_turkic(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, writeable);
134 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
135 if (is_ok) {
136 const ok_value = {};
137 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
138 return ok_value;
139 } else {
140 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
141 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
142 throw new diplomatRuntime.FFIError(throw_value);
143 }
144 })();
145 });
146 buf_arg_s.free();
147 return diplomat_out;
148 }
149
150 add_case_closure_to(arg_c, arg_builder) {
151 wasm.ICU4XCaseMapper_add_case_closure_to(this.underlying, diplomatRuntime.extractCodePoint(arg_c, 'arg_c'), arg_builder.underlying);
152 }
153
154 simple_lowercase(arg_ch) {
155 return wasm.ICU4XCaseMapper_simple_lowercase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch'));
156 }
157
158 simple_uppercase(arg_ch) {
159 return wasm.ICU4XCaseMapper_simple_uppercase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch'));
160 }
161
162 simple_titlecase(arg_ch) {
163 return wasm.ICU4XCaseMapper_simple_titlecase(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch'));
164 }
165
166 simple_fold(arg_ch) {
167 return wasm.ICU4XCaseMapper_simple_fold(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch'));
168 }
169
170 simple_fold_turkic(arg_ch) {
171 return wasm.ICU4XCaseMapper_simple_fold_turkic(this.underlying, diplomatRuntime.extractCodePoint(arg_ch, 'arg_ch'));
172 }
173 }