• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import wasm from "./diplomat-wasm.mjs";
3import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
5
6/** See the [Rust documentation for `SentenceBreak`](https://docs.rs/icu/latest/icu/properties/props/struct.SentenceBreak.html) for more information.
7*/
8
9
10export class SentenceBreak {
11
12    #value = undefined;
13
14    static #values = new Map([
15        ["Other", 0],
16        ["ATerm", 1],
17        ["Close", 2],
18        ["Format", 3],
19        ["Lower", 4],
20        ["Numeric", 5],
21        ["OLetter", 6],
22        ["Sep", 7],
23        ["Sp", 8],
24        ["STerm", 9],
25        ["Upper", 10],
26        ["Cr", 11],
27        ["Extend", 12],
28        ["Lf", 13],
29        ["SContinue", 14]
30    ]);
31
32    static getAllEntries() {
33        return SentenceBreak.#values.entries();
34    }
35
36    #internalConstructor(value) {
37        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
38            // We pass in two internalConstructor arguments to create *new*
39            // instances of this type, otherwise the enums are treated as singletons.
40            if (arguments[1] === diplomatRuntime.internalConstructor ) {
41                this.#value = arguments[2];
42                return this;
43            }
44            return SentenceBreak.#objectValues[arguments[1]];
45        }
46
47        if (value instanceof SentenceBreak) {
48            return value;
49        }
50
51        let intVal = SentenceBreak.#values.get(value);
52
53        // Nullish check, checks for null or undefined
54        if (intVal != null) {
55            return SentenceBreak.#objectValues[intVal];
56        }
57
58        throw TypeError(value + " is not a SentenceBreak and does not correspond to any of its enumerator values.");
59    }
60
61    static fromValue(value) {
62        return new SentenceBreak(value);
63    }
64
65    get value() {
66        return [...SentenceBreak.#values.keys()][this.#value];
67    }
68
69    get ffiValue() {
70        return this.#value;
71    }
72    static #objectValues = [
73        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
74        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
75        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
76        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
77        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
78        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
79        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
80        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
81        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
82        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
83        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
84        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
85        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
86        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13),
87        new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
88    ];
89
90    static Other = SentenceBreak.#objectValues[0];
91    static ATerm = SentenceBreak.#objectValues[1];
92    static Close = SentenceBreak.#objectValues[2];
93    static Format = SentenceBreak.#objectValues[3];
94    static Lower = SentenceBreak.#objectValues[4];
95    static Numeric = SentenceBreak.#objectValues[5];
96    static OLetter = SentenceBreak.#objectValues[6];
97    static Sep = SentenceBreak.#objectValues[7];
98    static Sp = SentenceBreak.#objectValues[8];
99    static STerm = SentenceBreak.#objectValues[9];
100    static Upper = SentenceBreak.#objectValues[10];
101    static Cr = SentenceBreak.#objectValues[11];
102    static Extend = SentenceBreak.#objectValues[12];
103    static Lf = SentenceBreak.#objectValues[13];
104    static SContinue = SentenceBreak.#objectValues[14];
105
106    static forChar(ch) {
107        const result = wasm.icu4x_SentenceBreak_for_char_mv1(ch);
108
109        try {
110            return new SentenceBreak(diplomatRuntime.internalConstructor, result);
111        }
112
113        finally {}
114    }
115
116    longName() {
117        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
118
119        const result = wasm.icu4x_SentenceBreak_long_name_mv1(diplomatReceive.buffer, this.ffiValue);
120
121        try {
122            if (!diplomatReceive.resultFlag) {
123                return null;
124            }
125            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
126        }
127
128        finally {
129            diplomatReceive.free();
130        }
131    }
132
133    shortName() {
134        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
135
136        const result = wasm.icu4x_SentenceBreak_short_name_mv1(diplomatReceive.buffer, this.ffiValue);
137
138        try {
139            if (!diplomatReceive.resultFlag) {
140                return null;
141            }
142            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
143        }
144
145        finally {
146            diplomatReceive.free();
147        }
148    }
149
150    toIntegerValue() {
151        const result = wasm.icu4x_SentenceBreak_to_integer_value_mv1(this.ffiValue);
152
153        try {
154            return result;
155        }
156
157        finally {}
158    }
159
160    static fromIntegerValue(other) {
161        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
162
163        const result = wasm.icu4x_SentenceBreak_from_integer_value_mv1(diplomatReceive.buffer, other);
164
165        try {
166            if (!diplomatReceive.resultFlag) {
167                return null;
168            }
169            return new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
170        }
171
172        finally {
173            diplomatReceive.free();
174        }
175    }
176
177    constructor(value) {
178        return this.#internalConstructor(...arguments)
179    }
180}