• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { DataError } from "./DataError.mjs"
3import { DataProvider } from "./DataProvider.mjs"
4import { Locale } from "./Locale.mjs"
5import wasm from "./diplomat-wasm.mjs";
6import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
8
9/** A set of "exemplar characters" for a given locale.
10*
11*See the [Rust documentation for `locale`](https://docs.rs/icu/latest/icu/locale/index.html) for more information.
12*
13*See the [Rust documentation for `ExemplarCharacters`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html) for more information.
14*
15*See the [Rust documentation for `ExemplarCharactersBorrowed`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharactersBorrowed.html) for more information.
16*/
17const ExemplarCharacters_box_destroy_registry = new FinalizationRegistry((ptr) => {
18    wasm.icu4x_ExemplarCharacters_destroy_mv1(ptr);
19});
20
21export class ExemplarCharacters {
22
23    // Internal ptr reference:
24    #ptr = null;
25
26    // Lifetimes are only to keep dependencies alive.
27    // Since JS won't garbage collect until there are no incoming edges.
28    #selfEdge = [];
29
30    #internalConstructor(symbol, ptr, selfEdge) {
31        if (symbol !== diplomatRuntime.internalConstructor) {
32            console.error("ExemplarCharacters is an Opaque type. You cannot call its constructor.");
33            return;
34        }
35
36        this.#ptr = ptr;
37        this.#selfEdge = selfEdge;
38
39        // Are we being borrowed? If not, we can register.
40        if (this.#selfEdge.length === 0) {
41            ExemplarCharacters_box_destroy_registry.register(this, this.#ptr);
42        }
43
44        return this;
45    }
46    get ffiValue() {
47        return this.#ptr;
48    }
49
50    containsStr(s) {
51        let functionCleanupArena = new diplomatRuntime.CleanupArena();
52
53        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
54
55        const result = wasm.icu4x_ExemplarCharacters_contains_str_mv1(this.ffiValue, ...sSlice.splat());
56
57        try {
58            return result;
59        }
60
61        finally {
62            functionCleanupArena.free();
63        }
64    }
65
66    contains(cp) {
67        const result = wasm.icu4x_ExemplarCharacters_contains_mv1(this.ffiValue, cp);
68
69        try {
70            return result;
71        }
72
73        finally {}
74    }
75
76    static createMain(locale) {
77        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
78
79        const result = wasm.icu4x_ExemplarCharacters_create_main_mv1(diplomatReceive.buffer, locale.ffiValue);
80
81        try {
82            if (!diplomatReceive.resultFlag) {
83                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
84                throw new globalThis.Error('DataError: ' + cause.value, { cause });
85            }
86            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
87        }
88
89        finally {
90            diplomatReceive.free();
91        }
92    }
93
94    static createMainWithProvider(provider, locale) {
95        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
96
97        const result = wasm.icu4x_ExemplarCharacters_create_main_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
98
99        try {
100            if (!diplomatReceive.resultFlag) {
101                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
102                throw new globalThis.Error('DataError: ' + cause.value, { cause });
103            }
104            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
105        }
106
107        finally {
108            diplomatReceive.free();
109        }
110    }
111
112    static createAuxiliary(locale) {
113        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
114
115        const result = wasm.icu4x_ExemplarCharacters_create_auxiliary_mv1(diplomatReceive.buffer, locale.ffiValue);
116
117        try {
118            if (!diplomatReceive.resultFlag) {
119                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
120                throw new globalThis.Error('DataError: ' + cause.value, { cause });
121            }
122            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
123        }
124
125        finally {
126            diplomatReceive.free();
127        }
128    }
129
130    static createAuxiliaryWithProvider(provider, locale) {
131        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
132
133        const result = wasm.icu4x_ExemplarCharacters_create_auxiliary_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
134
135        try {
136            if (!diplomatReceive.resultFlag) {
137                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
138                throw new globalThis.Error('DataError: ' + cause.value, { cause });
139            }
140            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
141        }
142
143        finally {
144            diplomatReceive.free();
145        }
146    }
147
148    static createPunctuation(locale) {
149        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
150
151        const result = wasm.icu4x_ExemplarCharacters_create_punctuation_mv1(diplomatReceive.buffer, locale.ffiValue);
152
153        try {
154            if (!diplomatReceive.resultFlag) {
155                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
156                throw new globalThis.Error('DataError: ' + cause.value, { cause });
157            }
158            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
159        }
160
161        finally {
162            diplomatReceive.free();
163        }
164    }
165
166    static createPunctuationWithProvider(provider, locale) {
167        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
168
169        const result = wasm.icu4x_ExemplarCharacters_create_punctuation_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
170
171        try {
172            if (!diplomatReceive.resultFlag) {
173                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
174                throw new globalThis.Error('DataError: ' + cause.value, { cause });
175            }
176            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
177        }
178
179        finally {
180            diplomatReceive.free();
181        }
182    }
183
184    static createNumbers(locale) {
185        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
186
187        const result = wasm.icu4x_ExemplarCharacters_create_numbers_mv1(diplomatReceive.buffer, locale.ffiValue);
188
189        try {
190            if (!diplomatReceive.resultFlag) {
191                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
192                throw new globalThis.Error('DataError: ' + cause.value, { cause });
193            }
194            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
195        }
196
197        finally {
198            diplomatReceive.free();
199        }
200    }
201
202    static createNumbersWithProvider(provider, locale) {
203        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
204
205        const result = wasm.icu4x_ExemplarCharacters_create_numbers_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
206
207        try {
208            if (!diplomatReceive.resultFlag) {
209                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
210                throw new globalThis.Error('DataError: ' + cause.value, { cause });
211            }
212            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
213        }
214
215        finally {
216            diplomatReceive.free();
217        }
218    }
219
220    static createIndex(locale) {
221        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
222
223        const result = wasm.icu4x_ExemplarCharacters_create_index_mv1(diplomatReceive.buffer, locale.ffiValue);
224
225        try {
226            if (!diplomatReceive.resultFlag) {
227                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
228                throw new globalThis.Error('DataError: ' + cause.value, { cause });
229            }
230            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
231        }
232
233        finally {
234            diplomatReceive.free();
235        }
236    }
237
238    static createIndexWithProvider(provider, locale) {
239        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
240
241        const result = wasm.icu4x_ExemplarCharacters_create_index_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
242
243        try {
244            if (!diplomatReceive.resultFlag) {
245                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
246                throw new globalThis.Error('DataError: ' + cause.value, { cause });
247            }
248            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
249        }
250
251        finally {
252            diplomatReceive.free();
253        }
254    }
255
256    constructor(symbol, ptr, selfEdge) {
257        return this.#internalConstructor(...arguments)
258    }
259}