• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { GeneralCategoryGroup } from "./GeneralCategoryGroup.mjs"
3import wasm from "./diplomat-wasm.mjs";
4import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
6
7/** See the [Rust documentation for `GeneralCategory`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategory.html) for more information.
8*/
9
10
11export class GeneralCategory {
12
13    #value = undefined;
14
15    static #values = new Map([
16        ["Unassigned", 0],
17        ["UppercaseLetter", 1],
18        ["LowercaseLetter", 2],
19        ["TitlecaseLetter", 3],
20        ["ModifierLetter", 4],
21        ["OtherLetter", 5],
22        ["NonspacingMark", 6],
23        ["SpacingMark", 8],
24        ["EnclosingMark", 7],
25        ["DecimalNumber", 9],
26        ["LetterNumber", 10],
27        ["OtherNumber", 11],
28        ["SpaceSeparator", 12],
29        ["LineSeparator", 13],
30        ["ParagraphSeparator", 14],
31        ["Control", 15],
32        ["Format", 16],
33        ["PrivateUse", 17],
34        ["Surrogate", 18],
35        ["DashPunctuation", 19],
36        ["OpenPunctuation", 20],
37        ["ClosePunctuation", 21],
38        ["ConnectorPunctuation", 22],
39        ["InitialPunctuation", 28],
40        ["FinalPunctuation", 29],
41        ["OtherPunctuation", 23],
42        ["MathSymbol", 24],
43        ["CurrencySymbol", 25],
44        ["ModifierSymbol", 26],
45        ["OtherSymbol", 27]
46    ]);
47
48    static getAllEntries() {
49        return GeneralCategory.#values.entries();
50    }
51
52    #internalConstructor(value) {
53        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
54            // We pass in two internalConstructor arguments to create *new*
55            // instances of this type, otherwise the enums are treated as singletons.
56            if (arguments[1] === diplomatRuntime.internalConstructor ) {
57                this.#value = arguments[2];
58                return this;
59            }
60            return GeneralCategory.#objectValues[arguments[1]];
61        }
62
63        if (value instanceof GeneralCategory) {
64            return value;
65        }
66
67        let intVal = GeneralCategory.#values.get(value);
68
69        // Nullish check, checks for null or undefined
70        if (intVal != null) {
71            return GeneralCategory.#objectValues[intVal];
72        }
73
74        throw TypeError(value + " is not a GeneralCategory and does not correspond to any of its enumerator values.");
75    }
76
77    static fromValue(value) {
78        return new GeneralCategory(value);
79    }
80
81    get value() {
82        for (let entry of GeneralCategory.#values) {
83            if (entry[1] == this.#value) {
84                return entry[0];
85            }
86        }
87    }
88
89    get ffiValue() {
90        return this.#value;
91    }
92    static #objectValues = {
93        [0]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
94        [1]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
95        [2]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
96        [3]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
97        [4]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
98        [5]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
99        [6]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
100        [8]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
101        [7]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
102        [9]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
103        [10]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
104        [11]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
105        [12]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
106        [13]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13),
107        [14]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
108        [15]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15),
109        [16]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16),
110        [17]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17),
111        [18]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 18),
112        [19]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 19),
113        [20]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 20),
114        [21]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 21),
115        [22]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 22),
116        [28]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 28),
117        [29]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 29),
118        [23]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 23),
119        [24]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 24),
120        [25]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 25),
121        [26]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 26),
122        [27]: new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 27),
123    };
124
125    static Unassigned = GeneralCategory.#objectValues[0];
126    static UppercaseLetter = GeneralCategory.#objectValues[1];
127    static LowercaseLetter = GeneralCategory.#objectValues[2];
128    static TitlecaseLetter = GeneralCategory.#objectValues[3];
129    static ModifierLetter = GeneralCategory.#objectValues[4];
130    static OtherLetter = GeneralCategory.#objectValues[5];
131    static NonspacingMark = GeneralCategory.#objectValues[6];
132    static SpacingMark = GeneralCategory.#objectValues[8];
133    static EnclosingMark = GeneralCategory.#objectValues[7];
134    static DecimalNumber = GeneralCategory.#objectValues[9];
135    static LetterNumber = GeneralCategory.#objectValues[10];
136    static OtherNumber = GeneralCategory.#objectValues[11];
137    static SpaceSeparator = GeneralCategory.#objectValues[12];
138    static LineSeparator = GeneralCategory.#objectValues[13];
139    static ParagraphSeparator = GeneralCategory.#objectValues[14];
140    static Control = GeneralCategory.#objectValues[15];
141    static Format = GeneralCategory.#objectValues[16];
142    static PrivateUse = GeneralCategory.#objectValues[17];
143    static Surrogate = GeneralCategory.#objectValues[18];
144    static DashPunctuation = GeneralCategory.#objectValues[19];
145    static OpenPunctuation = GeneralCategory.#objectValues[20];
146    static ClosePunctuation = GeneralCategory.#objectValues[21];
147    static ConnectorPunctuation = GeneralCategory.#objectValues[22];
148    static InitialPunctuation = GeneralCategory.#objectValues[28];
149    static FinalPunctuation = GeneralCategory.#objectValues[29];
150    static OtherPunctuation = GeneralCategory.#objectValues[23];
151    static MathSymbol = GeneralCategory.#objectValues[24];
152    static CurrencySymbol = GeneralCategory.#objectValues[25];
153    static ModifierSymbol = GeneralCategory.#objectValues[26];
154    static OtherSymbol = GeneralCategory.#objectValues[27];
155
156    static forChar(ch) {
157        const result = wasm.icu4x_GeneralCategory_for_char_mv1(ch);
158
159        try {
160            return new GeneralCategory(diplomatRuntime.internalConstructor, result);
161        }
162
163        finally {}
164    }
165
166    longName() {
167        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
168
169        const result = wasm.icu4x_GeneralCategory_long_name_mv1(diplomatReceive.buffer, this.ffiValue);
170
171        try {
172            if (!diplomatReceive.resultFlag) {
173                return null;
174            }
175            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
176        }
177
178        finally {
179            diplomatReceive.free();
180        }
181    }
182
183    shortName() {
184        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
185
186        const result = wasm.icu4x_GeneralCategory_short_name_mv1(diplomatReceive.buffer, this.ffiValue);
187
188        try {
189            if (!diplomatReceive.resultFlag) {
190                return null;
191            }
192            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
193        }
194
195        finally {
196            diplomatReceive.free();
197        }
198    }
199
200    toIntegerValue() {
201        const result = wasm.icu4x_GeneralCategory_to_integer_value_mv1(this.ffiValue);
202
203        try {
204            return result;
205        }
206
207        finally {}
208    }
209
210    toGroup() {
211        const result = wasm.icu4x_GeneralCategory_to_group_mv1(this.ffiValue);
212
213        try {
214            return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result);
215        }
216
217        finally {}
218    }
219
220    static fromIntegerValue(other) {
221        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
222
223        const result = wasm.icu4x_GeneralCategory_from_integer_value_mv1(diplomatReceive.buffer, other);
224
225        try {
226            if (!diplomatReceive.resultFlag) {
227                return null;
228            }
229            return new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
230        }
231
232        finally {
233            diplomatReceive.free();
234        }
235    }
236
237    constructor(value) {
238        return this.#internalConstructor(...arguments)
239    }
240}