GeneralCategory.mjs (11730B)
1 // generated by diplomat-tool 2 import { GeneralCategoryGroup } from "./GeneralCategoryGroup.mjs" 3 import wasm from "./diplomat-wasm.mjs"; 4 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 /** 8 * See the [Rust documentation for `GeneralCategory`](https://docs.rs/icu/latest/icu/properties/props/enum.GeneralCategory.html) for more information. 9 */ 10 11 12 export class GeneralCategory { 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 157 /** 158 * See the [Rust documentation for `for_char`](https://docs.rs/icu/latest/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information. 159 */ 160 static forChar(ch) { 161 162 const result = wasm.icu4x_GeneralCategory_for_char_mv1(ch); 163 164 try { 165 return new GeneralCategory(diplomatRuntime.internalConstructor, result); 166 } 167 168 finally { 169 } 170 } 171 172 /** 173 * Convert to an integer using the ICU4C integer mappings for `General_Category` 174 * Get the "long" name of this property value (returns empty if property value is unknown) 175 * 176 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesLongBorrowed.html#method.get) for more information. 177 */ 178 longName() { 179 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); 180 181 182 const result = wasm.icu4x_GeneralCategory_long_name_mv1(diplomatReceive.buffer, this.ffiValue); 183 184 try { 185 if (!diplomatReceive.resultFlag) { 186 return null; 187 } 188 return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer, "string8", []).getValue(); 189 } 190 191 finally { 192 diplomatReceive.free(); 193 } 194 } 195 196 /** 197 * Get the "short" name of this property value (returns empty if property value is unknown) 198 * 199 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesShortBorrowed.html#method.get) for more information. 200 */ 201 shortName() { 202 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); 203 204 205 const result = wasm.icu4x_GeneralCategory_short_name_mv1(diplomatReceive.buffer, this.ffiValue); 206 207 try { 208 if (!diplomatReceive.resultFlag) { 209 return null; 210 } 211 return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer, "string8", []).getValue(); 212 } 213 214 finally { 215 diplomatReceive.free(); 216 } 217 } 218 219 /** 220 * Convert to an integer value usable with ICU4C and CodePointMapData 221 */ 222 toIntegerValue() { 223 224 const result = wasm.icu4x_GeneralCategory_to_integer_value_mv1(this.ffiValue); 225 226 try { 227 return result; 228 } 229 230 finally { 231 } 232 } 233 234 /** 235 * Produces a GeneralCategoryGroup mask that can represent a group of general categories 236 * 237 * See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategoryGroup.html) for more information. 238 */ 239 toGroup() { 240 241 const result = wasm.icu4x_GeneralCategory_to_group_mv1(this.ffiValue); 242 243 try { 244 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 245 } 246 247 finally { 248 } 249 } 250 251 /** 252 * Convert from an integer using the ICU4C integer mappings for `General_Category` 253 * Convert from an integer value from ICU4C or CodePointMapData 254 */ 255 static fromIntegerValue(other) { 256 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 257 258 259 const result = wasm.icu4x_GeneralCategory_from_integer_value_mv1(diplomatReceive.buffer, other); 260 261 try { 262 if (!diplomatReceive.resultFlag) { 263 return null; 264 } 265 return new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 266 } 267 268 finally { 269 diplomatReceive.free(); 270 } 271 } 272 273 constructor(value) { 274 return this.#internalConstructor(...arguments) 275 } 276 }