1// generated by diplomat-tool 2import { CodePointSetBuilder } from "./CodePointSetBuilder.mjs" 3import { DataError } from "./DataError.mjs" 4import { DataProvider } from "./DataProvider.mjs" 5import { Locale } from "./Locale.mjs" 6import { TitlecaseOptions } from "./TitlecaseOptions.mjs" 7import wasm from "./diplomat-wasm.mjs"; 8import * as diplomatRuntime from "./diplomat-runtime.mjs"; 9 10 11/** See the [Rust documentation for `CaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html) for more information. 12*/ 13const CaseMapper_box_destroy_registry = new FinalizationRegistry((ptr) => { 14 wasm.icu4x_CaseMapper_destroy_mv1(ptr); 15}); 16 17export class CaseMapper { 18 19 // Internal ptr reference: 20 #ptr = null; 21 22 // Lifetimes are only to keep dependencies alive. 23 // Since JS won't garbage collect until there are no incoming edges. 24 #selfEdge = []; 25 26 #internalConstructor(symbol, ptr, selfEdge) { 27 if (symbol !== diplomatRuntime.internalConstructor) { 28 console.error("CaseMapper is an Opaque type. You cannot call its constructor."); 29 return; 30 } 31 32 this.#ptr = ptr; 33 this.#selfEdge = selfEdge; 34 35 // Are we being borrowed? If not, we can register. 36 if (this.#selfEdge.length === 0) { 37 CaseMapper_box_destroy_registry.register(this, this.#ptr); 38 } 39 40 return this; 41 } 42 get ffiValue() { 43 return this.#ptr; 44 } 45 46 #defaultConstructor() { 47 const result = wasm.icu4x_CaseMapper_create_mv1(); 48 49 try { 50 return new CaseMapper(diplomatRuntime.internalConstructor, result, []); 51 } 52 53 finally {} 54 } 55 56 static createWithProvider(provider) { 57 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 58 59 const result = wasm.icu4x_CaseMapper_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); 60 61 try { 62 if (!diplomatReceive.resultFlag) { 63 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 64 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 65 } 66 return new CaseMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); 67 } 68 69 finally { 70 diplomatReceive.free(); 71 } 72 } 73 74 lowercase(s, locale) { 75 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 76 77 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 78 79 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 80 wasm.icu4x_CaseMapper_lowercase_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, write.buffer); 81 82 try { 83 return write.readString8(); 84 } 85 86 finally { 87 functionCleanupArena.free(); 88 89 write.free(); 90 } 91 } 92 93 uppercase(s, locale) { 94 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 95 96 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 97 98 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 99 wasm.icu4x_CaseMapper_uppercase_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, write.buffer); 100 101 try { 102 return write.readString8(); 103 } 104 105 finally { 106 functionCleanupArena.free(); 107 108 write.free(); 109 } 110 } 111 112 titlecaseSegmentWithOnlyCaseData(s, locale, options) { 113 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 114 115 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 116 117 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 118 wasm.icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, ...TitlecaseOptions._fromSuppliedValue(diplomatRuntime.internalConstructor, options)._intoFFI(functionCleanupArena, {}), write.buffer); 119 120 try { 121 return write.readString8(); 122 } 123 124 finally { 125 functionCleanupArena.free(); 126 127 write.free(); 128 } 129 } 130 131 fold(s) { 132 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 133 134 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 135 136 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 137 wasm.icu4x_CaseMapper_fold_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); 138 139 try { 140 return write.readString8(); 141 } 142 143 finally { 144 functionCleanupArena.free(); 145 146 write.free(); 147 } 148 } 149 150 foldTurkic(s) { 151 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 152 153 const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); 154 155 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 156 wasm.icu4x_CaseMapper_fold_turkic_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); 157 158 try { 159 return write.readString8(); 160 } 161 162 finally { 163 functionCleanupArena.free(); 164 165 write.free(); 166 } 167 } 168 169 addCaseClosureTo(c, builder) {wasm.icu4x_CaseMapper_add_case_closure_to_mv1(this.ffiValue, c, builder.ffiValue); 170 171 try {} 172 173 finally {} 174 } 175 176 simpleLowercase(ch) { 177 const result = wasm.icu4x_CaseMapper_simple_lowercase_mv1(this.ffiValue, ch); 178 179 try { 180 return result; 181 } 182 183 finally {} 184 } 185 186 simpleUppercase(ch) { 187 const result = wasm.icu4x_CaseMapper_simple_uppercase_mv1(this.ffiValue, ch); 188 189 try { 190 return result; 191 } 192 193 finally {} 194 } 195 196 simpleTitlecase(ch) { 197 const result = wasm.icu4x_CaseMapper_simple_titlecase_mv1(this.ffiValue, ch); 198 199 try { 200 return result; 201 } 202 203 finally {} 204 } 205 206 simpleFold(ch) { 207 const result = wasm.icu4x_CaseMapper_simple_fold_mv1(this.ffiValue, ch); 208 209 try { 210 return result; 211 } 212 213 finally {} 214 } 215 216 simpleFoldTurkic(ch) { 217 const result = wasm.icu4x_CaseMapper_simple_fold_turkic_mv1(this.ffiValue, ch); 218 219 try { 220 return result; 221 } 222 223 finally {} 224 } 225 226 constructor() { 227 if (arguments[0] === diplomatRuntime.exposeConstructor) { 228 return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); 229 } else if (arguments[0] === diplomatRuntime.internalConstructor) { 230 return this.#internalConstructor(...arguments); 231 } else { 232 return this.#defaultConstructor(...arguments); 233 } 234 } 235}