• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { LeadingAdjustment } from "./LeadingAdjustment.mjs"
3import { TrailingCase } from "./TrailingCase.mjs"
4import wasm from "./diplomat-wasm.mjs";
5import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
7
8/** See the [Rust documentation for `TitlecaseOptions`](https://docs.rs/icu/latest/icu/casemap/options/struct.TitlecaseOptions.html) for more information.
9*/
10
11
12export class TitlecaseOptions {
13
14    #leadingAdjustment;
15
16    get leadingAdjustment()  {
17        return this.#leadingAdjustment;
18    }
19    set leadingAdjustment(value) {
20        this.#leadingAdjustment = value;
21    }
22
23    #trailingCase;
24
25    get trailingCase()  {
26        return this.#trailingCase;
27    }
28    set trailingCase(value) {
29        this.#trailingCase = value;
30    }
31
32    /** Create `TitlecaseOptions` from an object that contains all of `TitlecaseOptions`s fields.
33    * Optional fields do not need to be included in the provided object.
34    */
35    static fromFields(structObj) {
36        return new TitlecaseOptions(diplomatRuntime.exposeConstructor, structObj);
37    }
38
39    #internalConstructor(structObj) {
40        if (typeof structObj !== "object") {
41            throw new Error("TitlecaseOptions's constructor takes an object of TitlecaseOptions's fields.");
42        }
43
44        if ("leadingAdjustment" in structObj) {
45            this.#leadingAdjustment = structObj.leadingAdjustment;
46        } else {
47            this.#leadingAdjustment = null;
48        }
49
50        if ("trailingCase" in structObj) {
51            this.#trailingCase = structObj.trailingCase;
52        } else {
53            this.#trailingCase = null;
54        }
55
56        return this;
57    }
58
59    // Return this struct in FFI function friendly format.
60    // Returns an array that can be expanded with spread syntax (...)
61
62    _intoFFI(
63        functionCleanupArena,
64        appendArrayMap
65    ) {
66        return [...diplomatRuntime.optionToArgsForCalling(this.#leadingAdjustment, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]), ...diplomatRuntime.optionToArgsForCalling(this.#trailingCase, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)])]
67    }
68
69    static _fromSuppliedValue(internalConstructor, obj) {
70        if (internalConstructor !== diplomatRuntime.internalConstructor) {
71            throw new Error("_fromSuppliedValue cannot be called externally.");
72        }
73
74        if (obj instanceof TitlecaseOptions) {
75            return obj;
76        }
77
78        return TitlecaseOptions.fromFields(obj);
79    }
80
81    _writeToArrayBuffer(
82        arrayBuffer,
83        offset,
84        functionCleanupArena,
85        appendArrayMap
86    ) {
87        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#leadingAdjustment, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
88        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#trailingCase, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array));
89    }
90
91    // This struct contains borrowed fields, so this takes in a list of
92    // "edges" corresponding to where each lifetime's data may have been borrowed from
93    // and passes it down to individual fields containing the borrow.
94    // This method does not attempt to handle any dependencies between lifetimes, the caller
95    // should handle this when constructing edge arrays.
96    static _fromFFI(internalConstructor, ptr) {
97        if (internalConstructor !== diplomatRuntime.internalConstructor) {
98            throw new Error("TitlecaseOptions._fromFFI is not meant to be called externally. Please use the default constructor.");
99        }
100        let structObj = {};
101        const leadingAdjustmentDeref = ptr;
102        structObj.leadingAdjustment = diplomatRuntime.readOption(wasm, leadingAdjustmentDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new LeadingAdjustment(diplomatRuntime.internalConstructor, deref) });
103        const trailingCaseDeref = ptr + 8;
104        structObj.trailingCase = diplomatRuntime.readOption(wasm, trailingCaseDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new TrailingCase(diplomatRuntime.internalConstructor, deref) });
105
106        return new TitlecaseOptions(diplomatRuntime.exposeConstructor, structObj);
107    }
108
109    #defaultConstructor() {
110        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 16, 4, false);
111
112        const result = wasm.icu4x_TitlecaseOptionsV1_default_mv1(diplomatReceive.buffer);
113
114        try {
115            return TitlecaseOptions._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer);
116        }
117
118        finally {
119            diplomatReceive.free();
120        }
121    }
122
123    constructor() {
124        if (arguments[0] === diplomatRuntime.exposeConstructor) {
125            return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1));
126        } else if (arguments[0] === diplomatRuntime.internalConstructor) {
127            return this.#internalConstructor(...arguments);
128        } else {
129            return this.#defaultConstructor(...arguments);
130        }
131    }
132}