SentenceBreak.mjs (7721B)
1 // generated by diplomat-tool 2 import wasm from "./diplomat-wasm.mjs"; 3 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6 /** 7 * See the [Rust documentation for `SentenceBreak`](https://docs.rs/icu/latest/icu/properties/props/struct.SentenceBreak.html) for more information. 8 */ 9 10 11 export class SentenceBreak { 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 107 /** 108 * See the [Rust documentation for `for_char`](https://docs.rs/icu/latest/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information. 109 */ 110 static forChar(ch) { 111 112 const result = wasm.icu4x_SentenceBreak_for_char_mv1(ch); 113 114 try { 115 return new SentenceBreak(diplomatRuntime.internalConstructor, result); 116 } 117 118 finally { 119 } 120 } 121 122 /** 123 * Get the "long" name of this property value (returns empty if property value is unknown) 124 * 125 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesLongBorrowed.html#method.get) for more information. 126 */ 127 longName() { 128 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); 129 130 131 const result = wasm.icu4x_SentenceBreak_long_name_mv1(diplomatReceive.buffer, this.ffiValue); 132 133 try { 134 if (!diplomatReceive.resultFlag) { 135 return null; 136 } 137 return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer, "string8", []).getValue(); 138 } 139 140 finally { 141 diplomatReceive.free(); 142 } 143 } 144 145 /** 146 * Get the "short" name of this property value (returns empty if property value is unknown) 147 * 148 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/struct.PropertyNamesShortBorrowed.html#method.get) for more information. 149 */ 150 shortName() { 151 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true); 152 153 154 const result = wasm.icu4x_SentenceBreak_short_name_mv1(diplomatReceive.buffer, this.ffiValue); 155 156 try { 157 if (!diplomatReceive.resultFlag) { 158 return null; 159 } 160 return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer, "string8", []).getValue(); 161 } 162 163 finally { 164 diplomatReceive.free(); 165 } 166 } 167 168 /** 169 * Convert to an integer value usable with ICU4C and CodePointMapData 170 * 171 * See the [Rust documentation for `to_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.SentenceBreak.html#method.to_icu4c_value) for more information. 172 */ 173 toIntegerValue() { 174 175 const result = wasm.icu4x_SentenceBreak_to_integer_value_mv1(this.ffiValue); 176 177 try { 178 return result; 179 } 180 181 finally { 182 } 183 } 184 185 /** 186 * Convert from an integer value from ICU4C or CodePointMapData 187 * 188 * See the [Rust documentation for `from_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.SentenceBreak.html#method.from_icu4c_value) for more information. 189 */ 190 static fromIntegerValue(other) { 191 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 192 193 194 const result = wasm.icu4x_SentenceBreak_from_integer_value_mv1(diplomatReceive.buffer, other); 195 196 try { 197 if (!diplomatReceive.resultFlag) { 198 return null; 199 } 200 return new SentenceBreak(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 201 } 202 203 finally { 204 diplomatReceive.free(); 205 } 206 } 207 208 constructor(value) { 209 return this.#internalConstructor(...arguments) 210 } 211 }