• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { DataError } from "./DataError.mjs"
3import { DataProvider } from "./DataProvider.mjs"
4import wasm from "./diplomat-wasm.mjs";
5import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
7
8/** See the [Rust documentation for `DecomposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html) for more information.
9*/
10const DecomposingNormalizer_box_destroy_registry = new FinalizationRegistry((ptr) => {
11    wasm.icu4x_DecomposingNormalizer_destroy_mv1(ptr);
12});
13
14export class DecomposingNormalizer {
15
16    // Internal ptr reference:
17    #ptr = null;
18
19    // Lifetimes are only to keep dependencies alive.
20    // Since JS won't garbage collect until there are no incoming edges.
21    #selfEdge = [];
22
23    #internalConstructor(symbol, ptr, selfEdge) {
24        if (symbol !== diplomatRuntime.internalConstructor) {
25            console.error("DecomposingNormalizer is an Opaque type. You cannot call its constructor.");
26            return;
27        }
28
29        this.#ptr = ptr;
30        this.#selfEdge = selfEdge;
31
32        // Are we being borrowed? If not, we can register.
33        if (this.#selfEdge.length === 0) {
34            DecomposingNormalizer_box_destroy_registry.register(this, this.#ptr);
35        }
36
37        return this;
38    }
39    get ffiValue() {
40        return this.#ptr;
41    }
42
43    static createNfd() {
44        const result = wasm.icu4x_DecomposingNormalizer_create_nfd_mv1();
45
46        try {
47            return new DecomposingNormalizer(diplomatRuntime.internalConstructor, result, []);
48        }
49
50        finally {}
51    }
52
53    static createNfdWithProvider(provider) {
54        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
55
56        const result = wasm.icu4x_DecomposingNormalizer_create_nfd_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
57
58        try {
59            if (!diplomatReceive.resultFlag) {
60                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
61                throw new globalThis.Error('DataError: ' + cause.value, { cause });
62            }
63            return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
64        }
65
66        finally {
67            diplomatReceive.free();
68        }
69    }
70
71    static createNfkd() {
72        const result = wasm.icu4x_DecomposingNormalizer_create_nfkd_mv1();
73
74        try {
75            return new DecomposingNormalizer(diplomatRuntime.internalConstructor, result, []);
76        }
77
78        finally {}
79    }
80
81    static createNfkdWithProvider(provider) {
82        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
83
84        const result = wasm.icu4x_DecomposingNormalizer_create_nfkd_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue);
85
86        try {
87            if (!diplomatReceive.resultFlag) {
88                const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
89                throw new globalThis.Error('DataError: ' + cause.value, { cause });
90            }
91            return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
92        }
93
94        finally {
95            diplomatReceive.free();
96        }
97    }
98
99    normalize(s) {
100        let functionCleanupArena = new diplomatRuntime.CleanupArena();
101
102        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
103
104        const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
105        wasm.icu4x_DecomposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice.splat(), write.buffer);
106
107        try {
108            return write.readString8();
109        }
110
111        finally {
112            functionCleanupArena.free();
113
114            write.free();
115        }
116    }
117
118    isNormalized(s) {
119        let functionCleanupArena = new diplomatRuntime.CleanupArena();
120
121        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
122
123        const result = wasm.icu4x_DecomposingNormalizer_is_normalized_mv1(this.ffiValue, ...sSlice.splat());
124
125        try {
126            return result;
127        }
128
129        finally {
130            functionCleanupArena.free();
131        }
132    }
133
134    isNormalizedUtf16(s) {
135        let functionCleanupArena = new diplomatRuntime.CleanupArena();
136
137        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s));
138
139        const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice.splat());
140
141        try {
142            return result;
143        }
144
145        finally {
146            functionCleanupArena.free();
147        }
148    }
149
150    isNormalizedUpTo(s) {
151        let functionCleanupArena = new diplomatRuntime.CleanupArena();
152
153        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
154
155        const result = wasm.icu4x_DecomposingNormalizer_is_normalized_up_to_mv1(this.ffiValue, ...sSlice.splat());
156
157        try {
158            return result;
159        }
160
161        finally {
162            functionCleanupArena.free();
163        }
164    }
165
166    isNormalizedUtf16UpTo(s) {
167        let functionCleanupArena = new diplomatRuntime.CleanupArena();
168
169        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s));
170
171        const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice.splat());
172
173        try {
174            return result;
175        }
176
177        finally {
178            functionCleanupArena.free();
179        }
180    }
181
182    constructor(symbol, ptr, selfEdge) {
183        return this.#internalConstructor(...arguments)
184    }
185}