DecomposingNormalizer.mjs (8823B)
1 // generated by diplomat-tool 2 import { DataError } from "./DataError.mjs" 3 import { DataProvider } from "./DataProvider.mjs" 4 import wasm from "./diplomat-wasm.mjs"; 5 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8 /** 9 * See the [Rust documentation for `DecomposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html) for more information. 10 */ 11 const DecomposingNormalizer_box_destroy_registry = new FinalizationRegistry((ptr) => { 12 wasm.icu4x_DecomposingNormalizer_destroy_mv1(ptr); 13 }); 14 15 export class DecomposingNormalizer { 16 // Internal ptr reference: 17 #ptr = null; 18 19 // Lifetimes are only to keep dependencies alive. 20 // Since JS won't garbage collect until there are no incoming edges. 21 #selfEdge = []; 22 23 #internalConstructor(symbol, ptr, selfEdge) { 24 if (symbol !== diplomatRuntime.internalConstructor) { 25 console.error("DecomposingNormalizer is an Opaque type. You cannot call its constructor."); 26 return; 27 } 28 this.#ptr = ptr; 29 this.#selfEdge = selfEdge; 30 31 // Are we being borrowed? If not, we can register. 32 if (this.#selfEdge.length === 0) { 33 DecomposingNormalizer_box_destroy_registry.register(this, this.#ptr); 34 } 35 36 return this; 37 } 38 get ffiValue() { 39 return this.#ptr; 40 } 41 42 43 /** 44 * Construct a new DecomposingNormalizer instance for NFD using compiled data. 45 * 46 * See the [Rust documentation for `new_nfd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfd) for more information. 47 */ 48 static createNfd() { 49 50 const result = wasm.icu4x_DecomposingNormalizer_create_nfd_mv1(); 51 52 try { 53 return new DecomposingNormalizer(diplomatRuntime.internalConstructor, result, []); 54 } 55 56 finally { 57 } 58 } 59 60 /** 61 * Construct a new DecomposingNormalizer instance for NFD using a particular data source. 62 * 63 * See the [Rust documentation for `new_nfd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfd) for more information. 64 */ 65 static createNfdWithProvider(provider) { 66 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 67 68 69 const result = wasm.icu4x_DecomposingNormalizer_create_nfd_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 70 71 try { 72 if (!diplomatReceive.resultFlag) { 73 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 74 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 75 } 76 return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 77 } 78 79 finally { 80 diplomatReceive.free(); 81 } 82 } 83 84 /** 85 * Construct a new DecomposingNormalizer instance for NFKD using compiled data. 86 * 87 * See the [Rust documentation for `new_nfkd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfkd) for more information. 88 */ 89 static createNfkd() { 90 91 const result = wasm.icu4x_DecomposingNormalizer_create_nfkd_mv1(); 92 93 try { 94 return new DecomposingNormalizer(diplomatRuntime.internalConstructor, result, []); 95 } 96 97 finally { 98 } 99 } 100 101 /** 102 * Construct a new DecomposingNormalizer instance for NFKD using a particular data source. 103 * 104 * See the [Rust documentation for `new_nfkd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfkd) for more information. 105 */ 106 static createNfkdWithProvider(provider) { 107 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 108 109 110 const result = wasm.icu4x_DecomposingNormalizer_create_nfkd_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 111 112 try { 113 if (!diplomatReceive.resultFlag) { 114 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 115 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 116 } 117 return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 118 } 119 120 finally { 121 diplomatReceive.free(); 122 } 123 } 124 125 /** 126 * Normalize a string 127 * 128 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according 129 * to the WHATWG Encoding Standard. 130 * 131 * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.normalize_utf8) for more information. 132 */ 133 normalize(s) { 134 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 135 136 const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); 137 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 138 139 wasm.icu4x_DecomposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); 140 141 try { 142 return write.readString8(); 143 } 144 145 finally { 146 functionCleanupArena.free(); 147 148 write.free(); 149 } 150 } 151 152 /** 153 * Check if a string is normalized 154 * 155 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according 156 * to the WHATWG Encoding Standard. 157 * 158 * See the [Rust documentation for `is_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.is_normalized_utf8) for more information. 159 */ 160 isNormalized(s) { 161 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 162 163 const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); 164 165 const result = wasm.icu4x_DecomposingNormalizer_is_normalized_mv1(this.ffiValue, ...sSlice.splat()); 166 167 try { 168 return result; 169 } 170 171 finally { 172 functionCleanupArena.free(); 173 174 } 175 } 176 177 /** 178 * Check if a string is normalized 179 * 180 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according 181 * to the WHATWG Encoding Standard. 182 * 183 * See the [Rust documentation for `is_normalized_utf16`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.is_normalized_utf16) for more information. 184 */ 185 isNormalizedUtf16(s) { 186 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 187 188 const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); 189 190 const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice.splat()); 191 192 try { 193 return result; 194 } 195 196 finally { 197 functionCleanupArena.free(); 198 199 } 200 } 201 202 /** 203 * Return the index a slice of potentially-invalid UTF-8 is normalized up to 204 * 205 * See the [Rust documentation for `split_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.split_normalized_utf8) for more information. 206 * 207 * See the [Rust documentation for `split_normalized`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.split_normalized) for more information. 208 */ 209 isNormalizedUpTo(s) { 210 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 211 212 const sSlice = diplomatRuntime.DiplomatBuf.str8(wasm, s); 213 214 const result = wasm.icu4x_DecomposingNormalizer_is_normalized_up_to_mv1(this.ffiValue, ...sSlice.splat()); 215 216 try { 217 return result; 218 } 219 220 finally { 221 functionCleanupArena.free(); 222 223 } 224 } 225 226 /** 227 * Return the index a slice of potentially-invalid UTF-16 is normalized up to 228 * 229 * See the [Rust documentation for `split_normalized_utf16`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizerBorrowed.html#method.split_normalized_utf16) for more information. 230 */ 231 isNormalizedUtf16UpTo(s) { 232 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 233 234 const sSlice = diplomatRuntime.DiplomatBuf.str16(wasm, s); 235 236 const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice.splat()); 237 238 try { 239 return result; 240 } 241 242 finally { 243 functionCleanupArena.free(); 244 245 } 246 } 247 248 constructor(symbol, ptr, selfEdge) { 249 return this.#internalConstructor(...arguments) 250 } 251 }