CodePointMapData16.mjs (6002B)
1 // generated by diplomat-tool 2 import { CodePointRangeIterator } from "./CodePointRangeIterator.mjs" 3 import { CodePointSetData } from "./CodePointSetData.mjs" 4 import { DataError } from "./DataError.mjs" 5 import { DataProvider } from "./DataProvider.mjs" 6 import wasm from "./diplomat-wasm.mjs"; 7 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 8 9 10 /** 11 * 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. 12 * 13 * For properties whose values fit into 16 bits. 14 * 15 * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. 16 * 17 * See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapData.html) for more information. 18 * 19 * See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html) for more information. 20 */ 21 const CodePointMapData16_box_destroy_registry = new FinalizationRegistry((ptr) => { 22 wasm.icu4x_CodePointMapData16_destroy_mv1(ptr); 23 }); 24 25 export class CodePointMapData16 { 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 this.#ptr = ptr; 39 this.#selfEdge = selfEdge; 40 41 // Are we being borrowed? If not, we can register. 42 if (this.#selfEdge.length === 0) { 43 CodePointMapData16_box_destroy_registry.register(this, this.#ptr); 44 } 45 46 return this; 47 } 48 get ffiValue() { 49 return this.#ptr; 50 } 51 52 53 /** 54 * Gets the value for a code point. 55 * 56 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html#method.get) for more information. 57 */ 58 get(cp) { 59 60 const result = wasm.icu4x_CodePointMapData16_get_mv1(this.ffiValue, cp); 61 62 try { 63 return result; 64 } 65 66 finally { 67 } 68 } 69 70 /** 71 * Produces an iterator over ranges of code points that map to `value` 72 * 73 * See the [Rust documentation for `iter_ranges_for_value`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value) for more information. 74 */ 75 iterRangesForValue(value) { 76 // This lifetime edge depends on lifetimes 'a 77 let aEdges = [this]; 78 79 80 const result = wasm.icu4x_CodePointMapData16_iter_ranges_for_value_mv1(this.ffiValue, value); 81 82 try { 83 return new CodePointRangeIterator(diplomatRuntime.internalConstructor, result, [], aEdges); 84 } 85 86 finally { 87 } 88 } 89 90 /** 91 * Produces an iterator over ranges of code points that do not map to `value` 92 * 93 * See the [Rust documentation for `iter_ranges_for_value_complemented`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value_complemented) for more information. 94 */ 95 iterRangesForValueComplemented(value) { 96 // This lifetime edge depends on lifetimes 'a 97 let aEdges = [this]; 98 99 100 const result = wasm.icu4x_CodePointMapData16_iter_ranges_for_value_complemented_mv1(this.ffiValue, value); 101 102 try { 103 return new CodePointRangeIterator(diplomatRuntime.internalConstructor, result, [], aEdges); 104 } 105 106 finally { 107 } 108 } 109 110 /** 111 * Gets a [`CodePointSetData`] representing all entries in this map that map to the given value 112 * 113 * See the [Rust documentation for `get_set_for_value`](https://docs.rs/icu/latest/icu/properties/struct.CodePointMapDataBorrowed.html#method.get_set_for_value) for more information. 114 */ 115 getSetForValue(value) { 116 117 const result = wasm.icu4x_CodePointMapData16_get_set_for_value_mv1(this.ffiValue, value); 118 119 try { 120 return new CodePointSetData(diplomatRuntime.internalConstructor, result, []); 121 } 122 123 finally { 124 } 125 } 126 127 /** 128 * Create a map for the `Script` property, using compiled data. 129 * 130 * See the [Rust documentation for `Script`](https://docs.rs/icu/latest/icu/properties/props/struct.Script.html) for more information. 131 */ 132 static createScript() { 133 134 const result = wasm.icu4x_CodePointMapData16_create_script_mv1(); 135 136 try { 137 return new CodePointMapData16(diplomatRuntime.internalConstructor, result, []); 138 } 139 140 finally { 141 } 142 } 143 144 /** 145 * Create a map for the `Script` property, using a particular data source. 146 * 147 * See the [Rust documentation for `Script`](https://docs.rs/icu/latest/icu/properties/props/struct.Script.html) for more information. 148 */ 149 static createScriptWithProvider(provider) { 150 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 151 152 153 const result = wasm.icu4x_CodePointMapData16_create_script_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 154 155 try { 156 if (!diplomatReceive.resultFlag) { 157 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 158 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 159 } 160 return new CodePointMapData16(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 161 } 162 163 finally { 164 diplomatReceive.free(); 165 } 166 } 167 168 constructor(symbol, ptr, selfEdge) { 169 return this.#internalConstructor(...arguments) 170 } 171 }