Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XLocale.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 { ICU4XOrdering_js_to_rust, ICU4XOrdering_rust_to_js } from "./ICU4XOrdering.mjs"
5
6 const ICU4XLocale_box_destroy_registry = new FinalizationRegistry(underlying => {
7 wasm.ICU4XLocale_destroy(underlying);
8 });
9
10 export class ICU4XLocale {
11 #lifetimeEdges = [];
12 constructor(underlying, owned, edges) {
13 this.underlying = underlying;
14 this.#lifetimeEdges.push(...edges);
15 if (owned) {
16 ICU4XLocale_box_destroy_registry.register(this, underlying);
17 }
18 }
19
20 static create_from_string(arg_name) {
21 const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name);
22 const diplomat_out = (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XLocale_create_from_string(diplomat_receive_buffer, buf_arg_name.ptr, buf_arg_name.size);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XLocale(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 buf_arg_name.free();
37 return diplomat_out;
38 }
39
40 static create_und() {
41 return new ICU4XLocale(wasm.ICU4XLocale_create_und(), true, []);
42 }
43
44 clone() {
45 return new ICU4XLocale(wasm.ICU4XLocale_clone(this.underlying), true, []);
46 }
47
48 basename() {
49 return diplomatRuntime.withWriteable(wasm, (writeable) => {
50 return (() => {
51 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
52 wasm.ICU4XLocale_basename(diplomat_receive_buffer, this.underlying, writeable);
53 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
54 if (is_ok) {
55 const ok_value = {};
56 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
57 return ok_value;
58 } else {
59 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
60 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
61 throw new diplomatRuntime.FFIError(throw_value);
62 }
63 })();
64 });
65 }
66
67 get_unicode_extension(arg_bytes) {
68 const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes);
69 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
70 return (() => {
71 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
72 wasm.ICU4XLocale_get_unicode_extension(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size, writeable);
73 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
74 if (is_ok) {
75 const ok_value = {};
76 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
77 return ok_value;
78 } else {
79 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
80 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
81 throw new diplomatRuntime.FFIError(throw_value);
82 }
83 })();
84 });
85 buf_arg_bytes.free();
86 return diplomat_out;
87 }
88
89 language() {
90 return diplomatRuntime.withWriteable(wasm, (writeable) => {
91 return (() => {
92 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
93 wasm.ICU4XLocale_language(diplomat_receive_buffer, this.underlying, writeable);
94 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
95 if (is_ok) {
96 const ok_value = {};
97 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
98 return ok_value;
99 } else {
100 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
101 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
102 throw new diplomatRuntime.FFIError(throw_value);
103 }
104 })();
105 });
106 }
107
108 set_language(arg_bytes) {
109 const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes);
110 const diplomat_out = (() => {
111 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
112 wasm.ICU4XLocale_set_language(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size);
113 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
114 if (is_ok) {
115 const ok_value = {};
116 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
117 return ok_value;
118 } else {
119 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
120 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
121 throw new diplomatRuntime.FFIError(throw_value);
122 }
123 })();
124 buf_arg_bytes.free();
125 return diplomat_out;
126 }
127
128 region() {
129 return diplomatRuntime.withWriteable(wasm, (writeable) => {
130 return (() => {
131 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
132 wasm.ICU4XLocale_region(diplomat_receive_buffer, this.underlying, writeable);
133 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
134 if (is_ok) {
135 const ok_value = {};
136 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
137 return ok_value;
138 } else {
139 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
140 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
141 throw new diplomatRuntime.FFIError(throw_value);
142 }
143 })();
144 });
145 }
146
147 set_region(arg_bytes) {
148 const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes);
149 const diplomat_out = (() => {
150 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
151 wasm.ICU4XLocale_set_region(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size);
152 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
153 if (is_ok) {
154 const ok_value = {};
155 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
156 return ok_value;
157 } else {
158 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
159 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
160 throw new diplomatRuntime.FFIError(throw_value);
161 }
162 })();
163 buf_arg_bytes.free();
164 return diplomat_out;
165 }
166
167 script() {
168 return diplomatRuntime.withWriteable(wasm, (writeable) => {
169 return (() => {
170 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
171 wasm.ICU4XLocale_script(diplomat_receive_buffer, this.underlying, writeable);
172 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
173 if (is_ok) {
174 const ok_value = {};
175 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
176 return ok_value;
177 } else {
178 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
179 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
180 throw new diplomatRuntime.FFIError(throw_value);
181 }
182 })();
183 });
184 }
185
186 set_script(arg_bytes) {
187 const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes);
188 const diplomat_out = (() => {
189 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
190 wasm.ICU4XLocale_set_script(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size);
191 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
192 if (is_ok) {
193 const ok_value = {};
194 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
195 return ok_value;
196 } else {
197 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
198 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
199 throw new diplomatRuntime.FFIError(throw_value);
200 }
201 })();
202 buf_arg_bytes.free();
203 return diplomat_out;
204 }
205
206 static canonicalize(arg_bytes) {
207 const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes);
208 const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => {
209 return (() => {
210 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
211 wasm.ICU4XLocale_canonicalize(diplomat_receive_buffer, buf_arg_bytes.ptr, buf_arg_bytes.size, writeable);
212 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
213 if (is_ok) {
214 const ok_value = {};
215 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
216 return ok_value;
217 } else {
218 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
219 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
220 throw new diplomatRuntime.FFIError(throw_value);
221 }
222 })();
223 });
224 buf_arg_bytes.free();
225 return diplomat_out;
226 }
227
228 to_string() {
229 return diplomatRuntime.withWriteable(wasm, (writeable) => {
230 return (() => {
231 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
232 wasm.ICU4XLocale_to_string(diplomat_receive_buffer, this.underlying, writeable);
233 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
234 if (is_ok) {
235 const ok_value = {};
236 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
237 return ok_value;
238 } else {
239 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
240 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
241 throw new diplomatRuntime.FFIError(throw_value);
242 }
243 })();
244 });
245 }
246
247 normalizing_eq(arg_other) {
248 const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other);
249 const diplomat_out = wasm.ICU4XLocale_normalizing_eq(this.underlying, buf_arg_other.ptr, buf_arg_other.size);
250 buf_arg_other.free();
251 return diplomat_out;
252 }
253
254 strict_cmp(arg_other) {
255 const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other);
256 const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XLocale_strict_cmp(this.underlying, buf_arg_other.ptr, buf_arg_other.size)];
257 buf_arg_other.free();
258 return diplomat_out;
259 }
260
261 total_cmp(arg_other) {
262 return ICU4XOrdering_rust_to_js[wasm.ICU4XLocale_total_cmp(this.underlying, arg_other.underlying)];
263 }
264
265 static create_en() {
266 return new ICU4XLocale(wasm.ICU4XLocale_create_en(), true, []);
267 }
268
269 static create_bn() {
270 return new ICU4XLocale(wasm.ICU4XLocale_create_bn(), true, []);
271 }
272 }