// generated by diplomat-tool import { LocaleParseError } from "./LocaleParseError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; /** An ICU4X Locale, capable of representing strings like `"en-US"`. * *See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locale/struct.Locale.html) for more information. */ const Locale_box_destroy_registry = new FinalizationRegistry((ptr) => { wasm.icu4x_Locale_destroy_mv1(ptr); }); export class Locale { // Internal ptr reference: #ptr = null; // Lifetimes are only to keep dependencies alive. // Since JS won't garbage collect until there are no incoming edges. #selfEdge = []; constructor(symbol, ptr, selfEdge) { if (symbol !== diplomatRuntime.internalConstructor) { console.error("Locale is an Opaque type. You cannot call its constructor."); return; } this.#ptr = ptr; this.#selfEdge = selfEdge; // Are we being borrowed? If not, we can register. if (this.#selfEdge.length === 0) { Locale_box_destroy_registry.register(this, this.#ptr); } } get ffiValue() { return this.#ptr; } static fromString(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Locale_from_string_mv1(diplomatReceive.buffer, ...nameSlice.splat()); try { if (!diplomatReceive.resultFlag) { const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } return new Locale(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } finally { functionCleanupArena.free(); diplomatReceive.free(); } } static und() { const result = wasm.icu4x_Locale_und_mv1(); try { return new Locale(diplomatRuntime.internalConstructor, result, []); } finally {} } clone() { const result = wasm.icu4x_Locale_clone_mv1(this.ffiValue); try { return new Locale(diplomatRuntime.internalConstructor, result, []); } finally {} } get basename() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); wasm.icu4x_Locale_basename_mv1(this.ffiValue, write.buffer); try { return write.readString8(); } finally { write.free(); } } getUnicodeExtension(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); const result = wasm.icu4x_Locale_get_unicode_extension_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return result === 0 ? null : write.readString8(); } finally { functionCleanupArena.free(); write.free(); } } get language() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); wasm.icu4x_Locale_language_mv1(this.ffiValue, write.buffer); try { return write.readString8(); } finally { write.free(); } } set language(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Locale_set_language_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } } finally { functionCleanupArena.free(); diplomatReceive.free(); } } get region() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); const result = wasm.icu4x_Locale_region_mv1(this.ffiValue, write.buffer); try { return result === 0 ? null : write.readString8(); } finally { write.free(); } } set region(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Locale_set_region_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } } finally { functionCleanupArena.free(); diplomatReceive.free(); } } get script() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); const result = wasm.icu4x_Locale_script_mv1(this.ffiValue, write.buffer); try { return result === 0 ? null : write.readString8(); } finally { write.free(); } } set script(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_Locale_set_script_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } } finally { functionCleanupArena.free(); diplomatReceive.free(); } } static normalize(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); const result = wasm.icu4x_Locale_normalize_mv1(diplomatReceive.buffer, ...sSlice.splat(), write.buffer); try { if (!diplomatReceive.resultFlag) { const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } return write.readString8(); } finally { functionCleanupArena.free(); diplomatReceive.free(); write.free(); } } toString() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); wasm.icu4x_Locale_to_string_mv1(this.ffiValue, write.buffer); try { return write.readString8(); } finally { write.free(); } } normalizingEq(other) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const otherSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)); const result = wasm.icu4x_Locale_normalizing_eq_mv1(this.ffiValue, ...otherSlice.splat()); try { return result; } finally { functionCleanupArena.free(); } } compareToString(other) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const otherSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)); const result = wasm.icu4x_Locale_compare_to_string_mv1(this.ffiValue, ...otherSlice.splat()); try { return result; } finally { functionCleanupArena.free(); } } compareTo(other) { const result = wasm.icu4x_Locale_compare_to_mv1(this.ffiValue, other.ffiValue); try { return result; } finally {} } }