tor-browser

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

PluralCategory.mjs (4081B)


      1 // generated by diplomat-tool
      2 import wasm from "./diplomat-wasm.mjs";
      3 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      4 
      5 
      6 /**
      7 * See the [Rust documentation for `PluralCategory`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html) for more information.
      8 */
      9 
     10 
     11 export class PluralCategory {
     12    #value = undefined;
     13 
     14    static #values = new Map([
     15        ["Zero", 0],
     16        ["One", 1],
     17        ["Two", 2],
     18        ["Few", 3],
     19        ["Many", 4],
     20        ["Other", 5]
     21    ]);
     22 
     23    static getAllEntries() {
     24        return PluralCategory.#values.entries();
     25    }
     26 
     27    #internalConstructor(value) {
     28        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
     29            // We pass in two internalConstructor arguments to create *new*
     30            // instances of this type, otherwise the enums are treated as singletons.
     31            if (arguments[1] === diplomatRuntime.internalConstructor ) {
     32                this.#value = arguments[2];
     33                return this;
     34            }
     35            return PluralCategory.#objectValues[arguments[1]];
     36        }
     37 
     38        if (value instanceof PluralCategory) {
     39            return value;
     40        }
     41 
     42        let intVal = PluralCategory.#values.get(value);
     43 
     44        // Nullish check, checks for null or undefined
     45        if (intVal != null) {
     46            return PluralCategory.#objectValues[intVal];
     47        }
     48 
     49        throw TypeError(value + " is not a PluralCategory and does not correspond to any of its enumerator values.");
     50    }
     51 
     52    static fromValue(value) {
     53        return new PluralCategory(value);
     54    }
     55 
     56    get value(){
     57        return [...PluralCategory.#values.keys()][this.#value];
     58    }
     59 
     60    get ffiValue(){
     61        return this.#value;
     62    }
     63    static #objectValues = [
     64        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     65        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     66        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     67        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     68        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
     69        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
     70    ];
     71 
     72    static Zero = PluralCategory.#objectValues[0];
     73    static One = PluralCategory.#objectValues[1];
     74    static Two = PluralCategory.#objectValues[2];
     75    static Few = PluralCategory.#objectValues[3];
     76    static Many = PluralCategory.#objectValues[4];
     77    static Other = PluralCategory.#objectValues[5];
     78 
     79 
     80    /**
     81     * Construct from a string in the format
     82     * [specified in TR35](https://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules)
     83     *
     84     * See the [Rust documentation for `get_for_cldr_string`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html#method.get_for_cldr_string) for more information.
     85     *
     86     * See the [Rust documentation for `get_for_cldr_bytes`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html#method.get_for_cldr_bytes) for more information.
     87     */
     88    static getForCldrString(s) {
     89        let functionCleanupArena = new diplomatRuntime.CleanupArena();
     90 
     91        const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s);
     92        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
     93 
     94 
     95        const result = wasm.icu4x_PluralCategory_get_for_cldr_string_mv1(diplomatReceive.buffer, ...sSlice.splat());
     96 
     97        try {
     98            if (!diplomatReceive.resultFlag) {
     99                return null;
    100            }
    101            return new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
    102        }
    103 
    104        finally {
    105            functionCleanupArena.free();
    106 
    107            diplomatReceive.free();
    108        }
    109    }
    110 
    111    constructor(value) {
    112        return this.#internalConstructor(...arguments)
    113    }
    114 }