Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XCollator.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XCollatorAlternateHandling_js_to_rust, ICU4XCollatorAlternateHandling_rust_to_js } from "./ICU4XCollatorAlternateHandling.mjs"
4 import { ICU4XCollatorBackwardSecondLevel_js_to_rust, ICU4XCollatorBackwardSecondLevel_rust_to_js } from "./ICU4XCollatorBackwardSecondLevel.mjs"
5 import { ICU4XCollatorCaseFirst_js_to_rust, ICU4XCollatorCaseFirst_rust_to_js } from "./ICU4XCollatorCaseFirst.mjs"
6 import { ICU4XCollatorCaseLevel_js_to_rust, ICU4XCollatorCaseLevel_rust_to_js } from "./ICU4XCollatorCaseLevel.mjs"
7 import { ICU4XCollatorMaxVariable_js_to_rust, ICU4XCollatorMaxVariable_rust_to_js } from "./ICU4XCollatorMaxVariable.mjs"
8 import { ICU4XCollatorNumeric_js_to_rust, ICU4XCollatorNumeric_rust_to_js } from "./ICU4XCollatorNumeric.mjs"
9 import { ICU4XCollatorResolvedOptionsV1 } from "./ICU4XCollatorResolvedOptionsV1.mjs"
10 import { ICU4XCollatorStrength_js_to_rust, ICU4XCollatorStrength_rust_to_js } from "./ICU4XCollatorStrength.mjs"
11 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
12 import { ICU4XOrdering_js_to_rust, ICU4XOrdering_rust_to_js } from "./ICU4XOrdering.mjs"
13
14 const ICU4XCollator_box_destroy_registry = new FinalizationRegistry(underlying => {
15 wasm.ICU4XCollator_destroy(underlying);
16 });
17
18 export class ICU4XCollator {
19 #lifetimeEdges = [];
20 constructor(underlying, owned, edges) {
21 this.underlying = underlying;
22 this.#lifetimeEdges.push(...edges);
23 if (owned) {
24 ICU4XCollator_box_destroy_registry.register(this, underlying);
25 }
26 }
27
28 static create_v1(arg_provider, arg_locale, arg_options) {
29 const field_strength_arg_options = arg_options["strength"];
30 const field_alternate_handling_arg_options = arg_options["alternate_handling"];
31 const field_case_first_arg_options = arg_options["case_first"];
32 const field_max_variable_arg_options = arg_options["max_variable"];
33 const field_case_level_arg_options = arg_options["case_level"];
34 const field_numeric_arg_options = arg_options["numeric"];
35 const field_backward_second_level_arg_options = arg_options["backward_second_level"];
36 return (() => {
37 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
38 wasm.ICU4XCollator_create_v1(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying, ICU4XCollatorStrength_js_to_rust[field_strength_arg_options], ICU4XCollatorAlternateHandling_js_to_rust[field_alternate_handling_arg_options], ICU4XCollatorCaseFirst_js_to_rust[field_case_first_arg_options], ICU4XCollatorMaxVariable_js_to_rust[field_max_variable_arg_options], ICU4XCollatorCaseLevel_js_to_rust[field_case_level_arg_options], ICU4XCollatorNumeric_js_to_rust[field_numeric_arg_options], ICU4XCollatorBackwardSecondLevel_js_to_rust[field_backward_second_level_arg_options]);
39 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
40 if (is_ok) {
41 const ok_value = new ICU4XCollator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
42 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
43 return ok_value;
44 } else {
45 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
46 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
47 throw new diplomatRuntime.FFIError(throw_value);
48 }
49 })();
50 }
51
52 compare(arg_left, arg_right) {
53 const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left);
54 const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right);
55 const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)];
56 buf_arg_left.free();
57 buf_arg_right.free();
58 return diplomat_out;
59 }
60
61 compare_valid_utf8(arg_left, arg_right) {
62 const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left);
63 const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right);
64 const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare_valid_utf8(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)];
65 buf_arg_left.free();
66 buf_arg_right.free();
67 return diplomat_out;
68 }
69
70 compare_utf16(arg_left, arg_right) {
71 const buf_arg_left = diplomatRuntime.DiplomatBuf.str16(wasm, arg_left);
72 const buf_arg_right = diplomatRuntime.DiplomatBuf.str16(wasm, arg_right);
73 const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare_utf16(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)];
74 buf_arg_left.free();
75 buf_arg_right.free();
76 return diplomat_out;
77 }
78
79 resolved_options() {
80 return (() => {
81 const diplomat_receive_buffer = wasm.diplomat_alloc(28, 4);
82 wasm.ICU4XCollator_resolved_options(diplomat_receive_buffer, this.underlying);
83 const out = new ICU4XCollatorResolvedOptionsV1(diplomat_receive_buffer);
84 wasm.diplomat_free(diplomat_receive_buffer, 28, 4);
85 return out;
86 })();
87 }
88 }