• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs"
3import { CodePointSetData } from "./CodePointSetData.mjs"
4import { DataError } from "./DataError.mjs"
5import { DataProvider } from "./DataProvider.mjs"
6import wasm from "./diplomat-wasm.mjs";
7import * as diplomatRuntime from "./diplomat-runtime.mjs";
8
9
10/** An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property.
11*
12*For properties whose values fit into 16 bits.
13*
14*See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information.
15*
16*See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapData.html) for more information.
17*
18*See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html) for more information.
19*/
20const CodePointMapData16_box_destroy_registry = new FinalizationRegistry((ptr) => {
21    wasm.icu4x_CodePointMapData16_destroy_mv1(ptr);
22});
23
24export class CodePointMapData16 {
25
26    // Internal ptr reference:
27    #ptr = null;
28
29    // Lifetimes are only to keep dependencies alive.
30    // Since JS won't garbage collect until there are no incoming edges.
31    #selfEdge = [];
32
33    #internalConstructor(symbol, ptr, selfEdge) {
34        if (symbol !== diplomatRuntime.internalConstructor) {
35            console.error("CodePointMapData16 is an Opaque type. You cannot call its constructor.");
36            return;
37        }
38
39        this.#ptr = ptr;
40        this.#selfEdge = selfEdge;
41
42        // Are we being borrowed? If not, we can register.
43        if (this.#selfEdge.length === 0) {
44            CodePointMapData16_box_destroy_registry.register(this, this.#ptr);
45        }
46
47        return this;
48    }
49    get ffiValue() {
50        return this.#ptr;
51    }
52
53    get(cp) {
54        const result = wasm.icu4x_CodePointMapData16_get_mv1(this.ffiValue, cp);
55
56        try {
57            return result;
58        }
59
60        finally {}
61    }
62
63    iterRangesForValue(value) {
64        // This lifetime edge depends on lifetimes 'a
65        let aEdges = [this];
66
67        const result = wasm.icu4x_CodePointMapData16_iter_ranges_for_value_mv1(this.ffiValue, value);
68
69        try {
70            return new CodePointRangeIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
71        }
72
73        finally {}
74    }
75
76    iterRangesForValueComplemented(value) {
77        // This lifetime edge depends on lifetimes 'a
78        let aEdges = [this];
79
80        const result = wasm.icu4x_CodePointMapData16_iter_ranges_for_value_complemented_mv1(this.ffiValue, value);
81
82        try {
83            return new CodePointRangeIterator(diplomatRuntime.internalConstructor, result, [], aEdges);
84        }
85
86        finally {}
87    }
88
89    getSetForValue(value) {
90        const result = wasm.icu4x_CodePointMapData16_get_set_for_value_mv1(this.ffiValue, value);
91
92        try {
93            return new CodePointSetData(diplomatRuntime.internalConstructor, result, []);
94        }
95
96        finally {}
97    }
98
99    static createScript() {
100        const result = wasm.icu4x_CodePointMapData16_create_script_mv1();
101
102        try {
103            return new CodePointMapData16(diplomatRuntime.internalConstructor, result, []);
104        }
105
106        finally {}
107    }
108
109    static createScriptWithProvider(provider) {
110        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
111
112        const result = wasm.icu4x_CodePointMapData16_create_script_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
113
114        try {
115            if (!diplomatReceive.resultFlag) {
116                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
117                throw new globalThis.Error('DataError: ' + cause.value, { cause });
118            }
119            return new CodePointMapData16(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
120        }
121
122        finally {
123            diplomatReceive.free();
124        }
125    }
126
127    constructor(symbol, ptr, selfEdge) {
128        return this.#internalConstructor(...arguments)
129    }
130}