GraphemeClusterBreak.mjs (7081B)
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 `GraphemeClusterBreak`](https://docs.rs/icu/latest/icu/properties/props/struct.GraphemeClusterBreak.html) for more information. 8 */ 9 10 11 export class GraphemeClusterBreak { 12 #value = undefined; 13 14 static #values = new Map([ 15 ["Other", 0], 16 ["Control", 1], 17 ["Cr", 2], 18 ["Extend", 3], 19 ["L", 4], 20 ["Lf", 5], 21 ["Lv", 6], 22 ["Lvt", 7], 23 ["T", 8], 24 ["V", 9], 25 ["SpacingMark", 10], 26 ["Prepend", 11], 27 ["RegionalIndicator", 12], 28 ["EBase", 13], 29 ["EBaseGaz", 14], 30 ["EModifier", 15], 31 ["GlueAfterZwj", 16], 32 ["Zwj", 17] 33 ]); 34 35 static getAllEntries() { 36 return GraphemeClusterBreak.#values.entries(); 37 } 38 39 #internalConstructor(value) { 40 if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { 41 // We pass in two internalConstructor arguments to create *new* 42 // instances of this type, otherwise the enums are treated as singletons. 43 if (arguments[1] === diplomatRuntime.internalConstructor ) { 44 this.#value = arguments[2]; 45 return this; 46 } 47 return GraphemeClusterBreak.#objectValues[arguments[1]]; 48 } 49 50 if (value instanceof GraphemeClusterBreak) { 51 return value; 52 } 53 54 let intVal = GraphemeClusterBreak.#values.get(value); 55 56 // Nullish check, checks for null or undefined 57 if (intVal != null) { 58 return GraphemeClusterBreak.#objectValues[intVal]; 59 } 60 61 throw TypeError(value + " is not a GraphemeClusterBreak and does not correspond to any of its enumerator values."); 62 } 63 64 static fromValue(value) { 65 return new GraphemeClusterBreak(value); 66 } 67 68 get value(){ 69 return [...GraphemeClusterBreak.#values.keys()][this.#value]; 70 } 71 72 get ffiValue(){ 73 return this.#value; 74 } 75 static #objectValues = [ 76 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), 77 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), 78 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), 79 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), 80 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), 81 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), 82 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), 83 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), 84 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), 85 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9), 86 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10), 87 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11), 88 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12), 89 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13), 90 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14), 91 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15), 92 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16), 93 new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17), 94 ]; 95 96 static Other = GraphemeClusterBreak.#objectValues[0]; 97 static Control = GraphemeClusterBreak.#objectValues[1]; 98 static Cr = GraphemeClusterBreak.#objectValues[2]; 99 static Extend = GraphemeClusterBreak.#objectValues[3]; 100 static L = GraphemeClusterBreak.#objectValues[4]; 101 static Lf = GraphemeClusterBreak.#objectValues[5]; 102 static Lv = GraphemeClusterBreak.#objectValues[6]; 103 static Lvt = GraphemeClusterBreak.#objectValues[7]; 104 static T = GraphemeClusterBreak.#objectValues[8]; 105 static V = GraphemeClusterBreak.#objectValues[9]; 106 static SpacingMark = GraphemeClusterBreak.#objectValues[10]; 107 static Prepend = GraphemeClusterBreak.#objectValues[11]; 108 static RegionalIndicator = GraphemeClusterBreak.#objectValues[12]; 109 static EBase = GraphemeClusterBreak.#objectValues[13]; 110 static EBaseGaz = GraphemeClusterBreak.#objectValues[14]; 111 static EModifier = GraphemeClusterBreak.#objectValues[15]; 112 static GlueAfterZwj = GraphemeClusterBreak.#objectValues[16]; 113 static Zwj = GraphemeClusterBreak.#objectValues[17]; 114 115 116 /** 117 * See the [Rust documentation for `for_char`](https://docs.rs/icu/latest/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information. 118 */ 119 static forChar(ch) { 120 121 const result = wasm.icu4x_GraphemeClusterBreak_for_char_mv1(ch); 122 123 try { 124 return new GraphemeClusterBreak(diplomatRuntime.internalConstructor, result); 125 } 126 127 finally { 128 } 129 } 130 131 /** 132 * Convert to an integer value usable with ICU4C and CodePointMapData 133 * 134 * See the [Rust documentation for `to_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.GraphemeClusterBreak.html#method.to_icu4c_value) for more information. 135 */ 136 toIntegerValue() { 137 138 const result = wasm.icu4x_GraphemeClusterBreak_to_integer_value_mv1(this.ffiValue); 139 140 try { 141 return result; 142 } 143 144 finally { 145 } 146 } 147 148 /** 149 * Convert from an integer value from ICU4C or CodePointMapData 150 * 151 * See the [Rust documentation for `from_icu4c_value`](https://docs.rs/icu/latest/icu/properties/props/struct.GraphemeClusterBreak.html#method.from_icu4c_value) for more information. 152 */ 153 static fromIntegerValue(other) { 154 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 155 156 157 const result = wasm.icu4x_GraphemeClusterBreak_from_integer_value_mv1(diplomatReceive.buffer, other); 158 159 try { 160 if (!diplomatReceive.resultFlag) { 161 return null; 162 } 163 return new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 164 } 165 166 finally { 167 diplomatReceive.free(); 168 } 169 } 170 171 constructor(value) { 172 return this.#internalConstructor(...arguments) 173 } 174 }