tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ExemplarCharacters.mjs (14352B)


      1 // generated by diplomat-tool
      2 import { DataError } from "./DataError.mjs"
      3 import { DataProvider } from "./DataProvider.mjs"
      4 import { Locale } from "./Locale.mjs"
      5 import wasm from "./diplomat-wasm.mjs";
      6 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      7 
      8 
      9 /**
     10 * A set of "exemplar characters" for a given locale.
     11 *
     12 * See the [Rust documentation for `locale`](https://docs.rs/icu/latest/icu/locale/index.html) for more information.
     13 *
     14 * See the [Rust documentation for `ExemplarCharacters`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html) for more information.
     15 *
     16 * See the [Rust documentation for `ExemplarCharactersBorrowed`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharactersBorrowed.html) for more information.
     17 */
     18 const ExemplarCharacters_box_destroy_registry = new FinalizationRegistry((ptr) => {
     19    wasm.icu4x_ExemplarCharacters_destroy_mv1(ptr);
     20 });
     21 
     22 export class ExemplarCharacters {
     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        this.#ptr = ptr;
     36        this.#selfEdge = selfEdge;
     37 
     38        // Are we being borrowed? If not, we can register.
     39        if (this.#selfEdge.length === 0) {
     40            ExemplarCharacters_box_destroy_registry.register(this, this.#ptr);
     41        }
     42 
     43        return this;
     44    }
     45    get ffiValue() {
     46        return this.#ptr;
     47    }
     48 
     49 
     50    /**
     51     * Checks whether the string is in the set.
     52     *
     53     * See the [Rust documentation for `contains_str`](https://docs.rs/icu/latest/icu/collections/codepointinvliststringlist/struct.CodePointInversionListAndStringList.html#method.contains_str) for more information.
     54     */
     55    containsStr(s) {
     56        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     57 
     58        const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s);
     59 
     60        const result = wasm.icu4x_ExemplarCharacters_contains_str_mv1(this.ffiValue, ...sSlice.splat());
     61 
     62        try {
     63            return result;
     64        }
     65 
     66        finally {
     67            functionCleanupArena.free();
     68 
     69        }
     70    }
     71 
     72    /**
     73     * Checks whether the code point is in the set.
     74     *
     75     * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/collections/codepointinvliststringlist/struct.CodePointInversionListAndStringList.html#method.contains) for more information.
     76     */
     77    contains(cp) {
     78 
     79        const result = wasm.icu4x_ExemplarCharacters_contains_mv1(this.ffiValue, cp);
     80 
     81        try {
     82            return result;
     83        }
     84 
     85        finally {
     86        }
     87    }
     88 
     89    /**
     90     * Create an [`ExemplarCharacters`] for the "main" set of exemplar characters for a given locale, using compiled data.
     91     *
     92     * See the [Rust documentation for `try_new_main`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_main) for more information.
     93     */
     94    static createMain(locale) {
     95        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     96 
     97 
     98        const result = wasm.icu4x_ExemplarCharacters_create_main_mv1(diplomatReceive.buffer, locale.ffiValue);
     99 
    100        try {
    101            if (!diplomatReceive.resultFlag) {
    102                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    103                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    104            }
    105            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    106        }
    107 
    108        finally {
    109            diplomatReceive.free();
    110        }
    111    }
    112 
    113    /**
    114     * Create an [`ExemplarCharacters`] for the "main" set of exemplar characters for a given locale, using a particular data source
    115     *
    116     * See the [Rust documentation for `try_new_main`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_main) for more information.
    117     */
    118    static createMainWithProvider(provider, locale) {
    119        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    120 
    121 
    122        const result = wasm.icu4x_ExemplarCharacters_create_main_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
    123 
    124        try {
    125            if (!diplomatReceive.resultFlag) {
    126                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    127                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    128            }
    129            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    130        }
    131 
    132        finally {
    133            diplomatReceive.free();
    134        }
    135    }
    136 
    137    /**
    138     * Create an [`ExemplarCharacters`] for the "auxiliary" set of exemplar characters for a given locale, using compiled data.
    139     *
    140     * See the [Rust documentation for `try_new_auxiliary`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_auxiliary) for more information.
    141     */
    142    static createAuxiliary(locale) {
    143        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    144 
    145 
    146        const result = wasm.icu4x_ExemplarCharacters_create_auxiliary_mv1(diplomatReceive.buffer, locale.ffiValue);
    147 
    148        try {
    149            if (!diplomatReceive.resultFlag) {
    150                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    151                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    152            }
    153            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    154        }
    155 
    156        finally {
    157            diplomatReceive.free();
    158        }
    159    }
    160 
    161    /**
    162     * Create an [`ExemplarCharacters`] for the "auxiliary" set of exemplar characters for a given locale, using compiled data.
    163     *
    164     * See the [Rust documentation for `try_new_auxiliary`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_auxiliary) for more information.
    165     */
    166    static createAuxiliaryWithProvider(provider, locale) {
    167        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    168 
    169 
    170        const result = wasm.icu4x_ExemplarCharacters_create_auxiliary_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
    171 
    172        try {
    173            if (!diplomatReceive.resultFlag) {
    174                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    175                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    176            }
    177            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    178        }
    179 
    180        finally {
    181            diplomatReceive.free();
    182        }
    183    }
    184 
    185    /**
    186     * Create an [`ExemplarCharacters`] for the "punctuation" set of exemplar characters for a given locale, using compiled data.
    187     *
    188     * See the [Rust documentation for `try_new_punctuation`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_punctuation) for more information.
    189     */
    190    static createPunctuation(locale) {
    191        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    192 
    193 
    194        const result = wasm.icu4x_ExemplarCharacters_create_punctuation_mv1(diplomatReceive.buffer, locale.ffiValue);
    195 
    196        try {
    197            if (!diplomatReceive.resultFlag) {
    198                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    199                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    200            }
    201            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    202        }
    203 
    204        finally {
    205            diplomatReceive.free();
    206        }
    207    }
    208 
    209    /**
    210     * Create an [`ExemplarCharacters`] for the "punctuation" set of exemplar characters for a given locale, using compiled data.
    211     *
    212     * See the [Rust documentation for `try_new_punctuation`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_punctuation) for more information.
    213     */
    214    static createPunctuationWithProvider(provider, locale) {
    215        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    216 
    217 
    218        const result = wasm.icu4x_ExemplarCharacters_create_punctuation_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
    219 
    220        try {
    221            if (!diplomatReceive.resultFlag) {
    222                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    223                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    224            }
    225            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    226        }
    227 
    228        finally {
    229            diplomatReceive.free();
    230        }
    231    }
    232 
    233    /**
    234     * Create an [`ExemplarCharacters`] for the "numbers" set of exemplar characters for a given locale, using compiled data.
    235     *
    236     * See the [Rust documentation for `try_new_numbers`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_numbers) for more information.
    237     */
    238    static createNumbers(locale) {
    239        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    240 
    241 
    242        const result = wasm.icu4x_ExemplarCharacters_create_numbers_mv1(diplomatReceive.buffer, locale.ffiValue);
    243 
    244        try {
    245            if (!diplomatReceive.resultFlag) {
    246                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    247                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    248            }
    249            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    250        }
    251 
    252        finally {
    253            diplomatReceive.free();
    254        }
    255    }
    256 
    257    /**
    258     * Create an [`ExemplarCharacters`] for the "numbers" set of exemplar characters for a given locale, using compiled data.
    259     *
    260     * See the [Rust documentation for `try_new_numbers`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_numbers) for more information.
    261     */
    262    static createNumbersWithProvider(provider, locale) {
    263        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    264 
    265 
    266        const result = wasm.icu4x_ExemplarCharacters_create_numbers_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
    267 
    268        try {
    269            if (!diplomatReceive.resultFlag) {
    270                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    271                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    272            }
    273            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    274        }
    275 
    276        finally {
    277            diplomatReceive.free();
    278        }
    279    }
    280 
    281    /**
    282     * Create an [`ExemplarCharacters`] for the "index" set of exemplar characters for a given locale, using compiled data.
    283     *
    284     * See the [Rust documentation for `try_new_index`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_index) for more information.
    285     */
    286    static createIndex(locale) {
    287        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    288 
    289 
    290        const result = wasm.icu4x_ExemplarCharacters_create_index_mv1(diplomatReceive.buffer, locale.ffiValue);
    291 
    292        try {
    293            if (!diplomatReceive.resultFlag) {
    294                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    295                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    296            }
    297            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    298        }
    299 
    300        finally {
    301            diplomatReceive.free();
    302        }
    303    }
    304 
    305    /**
    306     * Create an [`ExemplarCharacters`] for the "index" set of exemplar characters for a given locale, using compiled data.
    307     *
    308     * See the [Rust documentation for `try_new_index`](https://docs.rs/icu/latest/icu/locale/exemplar_chars/struct.ExemplarCharacters.html#method.try_new_index) for more information.
    309     */
    310    static createIndexWithProvider(provider, locale) {
    311        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
    312 
    313 
    314        const result = wasm.icu4x_ExemplarCharacters_create_index_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue, locale.ffiValue);
    315 
    316        try {
    317            if (!diplomatReceive.resultFlag) {
    318                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    319                throw new globalThis.Error('DataError: ' + cause.value, { cause });
    320            }
    321            return new ExemplarCharacters(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
    322        }
    323 
    324        finally {
    325            diplomatReceive.free();
    326        }
    327    }
    328 
    329    constructor(symbol, ptr, selfEdge) {
    330        return this.#internalConstructor(...arguments)
    331    }
    332 }