Debian Codegraph @

third_party/rust/encoding_c/include/encoding_rs.h

raw
1 // Copyright Mozilla Foundation. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 // THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
11 // Instead, please regenerate using encoding_c/build.rs.
12
13 #ifndef cheddar_generated_encoding_rs_h
14 #define cheddar_generated_encoding_rs_h
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include "encoding_rs_statics.h"
23
24 /// Implements the
25 /// [_get an encoding_](https://encoding.spec.whatwg.org/#concept-encoding-get)
26 /// algorithm.
27 ///
28 /// If, after ASCII-lowercasing and removing leading and trailing
29 /// whitespace, the argument matches a label defined in the ENCODING_RS_ENCODING
30 /// Standard, `const ENCODING_RS_ENCODING*` representing the corresponding
31 /// encoding is returned. If there is no match, `NULL` is returned.
32 ///
33 /// This is the right function to use if the action upon the method returning
34 /// `NULL` is to use a fallback encoding (e.g. `WINDOWS_1252_ENCODING`) instead.
35 /// When the action upon the method returning `NULL` is not to proceed with
36 /// a fallback but to refuse processing, `encoding_for_label_no_replacement()`
37 /// is more appropriate.
38 ///
39 /// The argument buffer can be in any ASCII-compatible encoding. It is not
40 /// required to be UTF-8.
41 ///
42 /// `label` must be non-`NULL` even if `label_len` is zero. When `label_len`
43 /// is zero, it is OK for `label` to be something non-dereferencable,
44 /// such as `0x1`. This is required due to Rust's optimization for slices
45 /// within `Option`.
46 ///
47 /// # Undefined behavior
48 ///
49 /// UB ensues if `label` and `label_len` don't designate a valid memory block
50 /// of if `label` is `NULL`.
51 ENCODING_RS_ENCODING const* encoding_for_label(uint8_t const* label,
52 size_t label_len);
53
54 /// This function behaves the same as `encoding_for_label()`, except when
55 /// `encoding_for_label()` would return `REPLACEMENT_ENCODING`, this method
56 /// returns `NULL` instead.
57 ///
58 /// This method is useful in scenarios where a fatal error is required
59 /// upon invalid label, because in those cases the caller typically wishes
60 /// to treat the labels that map to the replacement encoding as fatal
61 /// errors, too.
62 ///
63 /// It is not OK to use this funciton when the action upon the method returning
64 /// `NULL` is to use a fallback encoding (e.g. `WINDOWS_1252_ENCODING`). In
65 /// such a case, the `encoding_for_label()` function should be used instead
66 /// in order to avoid unsafe fallback for labels that `encoding_for_label()`
67 /// maps to `REPLACEMENT_ENCODING`.
68 ///
69 /// The argument buffer can be in any ASCII-compatible encoding. It is not
70 /// required to be UTF-8.
71 ///
72 /// `label` must be non-`NULL` even if `label_len` is zero. When `label_len`
73 /// is zero, it is OK for `label` to be something non-dereferencable,
74 /// such as `0x1`. This is required due to Rust's optimization for slices
75 /// within `Option`.
76 ///
77 /// # Undefined behavior
78 ///
79 /// UB ensues if `label` and `label_len` don't designate a valid memory block
80 /// of if `label` is `NULL`.
81 ENCODING_RS_ENCODING const* encoding_for_label_no_replacement(
82 uint8_t const* label, size_t label_len);
83
84 /// Performs non-incremental BOM sniffing.
85 ///
86 /// The argument must either be a buffer representing the entire input
87 /// stream (non-streaming case) or a buffer representing at least the first
88 /// three bytes of the input stream (streaming case).
89 ///
90 /// Returns `UTF_8_ENCODING`, `UTF_16LE_ENCODING` or `UTF_16BE_ENCODING` if the
91 /// argument starts with the UTF-8, UTF-16LE or UTF-16BE BOM or `NULL`
92 /// otherwise. Upon return, `*buffer_len` is the length of the BOM (zero if
93 /// there is no BOM).
94 ///
95 /// `buffer` must be non-`NULL` even if `*buffer_len` is zero. When
96 /// `*buffer_len` is zero, it is OK for `buffer` to be something
97 /// non-dereferencable, such as `0x1`. This is required due to Rust's
98 /// optimization for slices within `Option`.
99 ///
100 /// # Undefined behavior
101 ///
102 /// UB ensues if `buffer` and `*buffer_len` don't designate a valid memory
103 /// block of if `buffer` is `NULL`.
104 ENCODING_RS_ENCODING const* encoding_for_bom(uint8_t const* buffer,
105 size_t* buffer_len);
106
107 /// Writes the name of the given `ENCODING_RS_ENCODING` to a caller-supplied
108 /// buffer as ASCII and returns the number of bytes / ASCII characters written.
109 ///
110 /// The output is not null-terminated.
111 ///
112 /// The caller _MUST_ ensure that `name_out` points to a buffer whose length
113 /// is at least `ENCODING_NAME_MAX_LENGTH` bytes.
114 ///
115 /// # Undefined behavior
116 ///
117 /// UB ensues if either argument is `NULL` or if `name_out` doesn't point to
118 /// a valid block of memory whose length is at least
119 /// `ENCODING_NAME_MAX_LENGTH` bytes.
120 size_t encoding_name(ENCODING_RS_ENCODING const* encoding, uint8_t* name_out);
121
122 /// Checks whether the _output encoding_ of this encoding can encode every
123 /// Unicode scalar. (Only true if the output encoding is UTF-8.)
124 ///
125 /// # Undefined behavior
126 ///
127 /// UB ensues if the argument is `NULL`.
128 bool encoding_can_encode_everything(ENCODING_RS_ENCODING const* encoding);
129
130 /// Checks whether the bytes 0x00...0x7F map exclusively to the characters
131 /// U+0000...U+007F and vice versa.
132 ///
133 /// # Undefined behavior
134 ///
135 /// UB ensues if the argument is `NULL`.
136 bool encoding_is_ascii_compatible(ENCODING_RS_ENCODING const* encoding);
137
138 /// Checks whether this encoding maps one byte to one Basic Multilingual
139 /// Plane code point (i.e. byte length equals decoded UTF-16 length) and
140 /// vice versa (for mappable characters).
141 ///
142 /// `true` iff this encoding is on the list of [Legacy single-byte
143 /// encodings](https://encoding.spec.whatwg.org/#legacy-single-byte-encodings)
144 /// in the spec or x-user-defined.
145 ///
146 /// # Undefined behavior
147 ///
148 /// UB ensues if the argument is `NULL`.
149 bool encoding_is_single_byte(ENCODING_RS_ENCODING const* encoding);
150
151 /// Returns the _output encoding_ of this encoding. This is UTF-8 for
152 /// UTF-16BE, UTF-16LE and replacement and the encoding itself otherwise.
153 ///
154 /// # Undefined behavior
155 ///
156 /// UB ensues if the argument is `NULL`.
157 ENCODING_RS_ENCODING const* encoding_output_encoding(
158 ENCODING_RS_ENCODING const* encoding);
159
160 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
161 /// on the heap with BOM sniffing enabled and returns a pointer to the
162 /// newly-allocated `ENCODING_RS_DECODER`.
163 ///
164 /// BOM sniffing may cause the returned decoder to morph into a decoder
165 /// for UTF-8, UTF-16LE or UTF-16BE instead of this encoding.
166 ///
167 /// Once the allocated `ENCODING_RS_DECODER` is no longer needed, the caller
168 /// _MUST_ deallocate it by passing the pointer returned by this function to
169 /// `decoder_free()`.
170 ///
171 /// # Undefined behavior
172 ///
173 /// UB ensues if the argument is `NULL`.
174 ENCODING_RS_DECODER* encoding_new_decoder(ENCODING_RS_ENCODING const* encoding);
175
176 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
177 /// on the heap with BOM removal and returns a pointer to the newly-allocated
178 /// `ENCODING_RS_DECODER`.
179 ///
180 /// If the input starts with bytes that are the BOM for this encoding,
181 /// those bytes are removed. However, the decoder never morphs into a
182 /// decoder for another encoding: A BOM for another encoding is treated as
183 /// (potentially malformed) input to the decoding algorithm for this
184 /// encoding.
185 ///
186 /// Once the allocated `ENCODING_RS_DECODER` is no longer needed, the caller
187 /// _MUST_ deallocate it by passing the pointer returned by this function to
188 /// `decoder_free()`.
189 ///
190 /// # Undefined behavior
191 ///
192 /// UB ensues if the argument is `NULL`.
193 ENCODING_RS_DECODER* encoding_new_decoder_with_bom_removal(
194 ENCODING_RS_ENCODING const* encoding);
195
196 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
197 /// on the heap with BOM handling disabled and returns a pointer to the
198 /// newly-allocated `ENCODING_RS_DECODER`.
199 ///
200 /// If the input starts with bytes that look like a BOM, those bytes are
201 /// not treated as a BOM. (Hence, the decoder never morphs into a decoder
202 /// for another encoding.)
203 ///
204 /// _Note:_ If the caller has performed BOM sniffing on its own but has not
205 /// removed the BOM, the caller should use
206 /// `encoding_new_decoder_with_bom_removal()` instead of this function to cause
207 /// the BOM to be removed.
208 ///
209 /// Once the allocated `ENCODING_RS_DECODER` is no longer needed, the caller
210 /// _MUST_ deallocate it by passing the pointer returned by this function to
211 /// `decoder_free()`.
212 ///
213 /// # Undefined behavior
214 ///
215 /// UB ensues if the argument is `NULL`.
216 ENCODING_RS_DECODER* encoding_new_decoder_without_bom_handling(
217 ENCODING_RS_ENCODING const* encoding);
218
219 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
220 /// into memory provided by the caller with BOM sniffing enabled. (In practice,
221 /// the target should likely be a pointer previously returned by
222 /// `encoding_new_decoder()`.)
223 ///
224 /// Note: If the caller has already performed BOM sniffing but has
225 /// not removed the BOM, the caller should still use this function in
226 /// order to cause the BOM to be ignored.
227 ///
228 /// # Undefined behavior
229 ///
230 /// UB ensues if either argument is `NULL`.
231 void encoding_new_decoder_into(ENCODING_RS_ENCODING const* encoding,
232 ENCODING_RS_DECODER* decoder);
233
234 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
235 /// into memory provided by the caller with BOM removal.
236 ///
237 /// If the input starts with bytes that are the BOM for this encoding,
238 /// those bytes are removed. However, the decoder never morphs into a
239 /// decoder for another encoding: A BOM for another encoding is treated as
240 /// (potentially malformed) input to the decoding algorithm for this
241 /// encoding.
242 ///
243 /// Once the allocated `ENCODING_RS_DECODER` is no longer needed, the caller
244 /// _MUST_ deallocate it by passing the pointer returned by this function to
245 /// `decoder_free()`.
246 ///
247 /// # Undefined behavior
248 ///
249 /// UB ensues if either argument is `NULL`.
250 void encoding_new_decoder_with_bom_removal_into(
251 ENCODING_RS_ENCODING const* encoding, ENCODING_RS_DECODER* decoder);
252
253 /// Allocates a new `ENCODING_RS_DECODER` for the given `ENCODING_RS_ENCODING`
254 /// into memory provided by the caller with BOM handling disabled.
255 ///
256 /// If the input starts with bytes that look like a BOM, those bytes are
257 /// not treated as a BOM. (Hence, the decoder never morphs into a decoder
258 /// for another encoding.)
259 ///
260 /// _Note:_ If the caller has performed BOM sniffing on its own but has not
261 /// removed the BOM, the caller should use
262 /// `encoding_new_decoder_with_bom_removal_into()` instead of this function to
263 /// cause the BOM to be removed.
264 ///
265 /// # Undefined behavior
266 ///
267 /// UB ensues if either argument is `NULL`.
268 void encoding_new_decoder_without_bom_handling_into(
269 ENCODING_RS_ENCODING const* encoding, ENCODING_RS_DECODER* decoder);
270
271 /// Allocates a new `ENCODING_RS_ENCODER` for the given `ENCODING_RS_ENCODING`
272 /// on the heap and returns a pointer to the newly-allocated
273 /// `ENCODING_RS_ENCODER`. (Exception, if the `ENCODING_RS_ENCODING` is
274 /// `replacement`, a new `ENCODING_RS_DECODER` for UTF-8 is instantiated (and
275 /// that `ENCODING_RS_DECODER` reports `UTF_8` as its `ENCODING_RS_ENCODING`).
276 ///
277 /// Once the allocated `ENCODING_RS_ENCODER` is no longer needed, the caller
278 /// _MUST_ deallocate it by passing the pointer returned by this function to
279 /// `encoder_free()`.
280 ///
281 /// # Undefined behavior
282 ///
283 /// UB ensues if the argument is `NULL`.
284 ENCODING_RS_ENCODER* encoding_new_encoder(ENCODING_RS_ENCODING const* encoding);
285
286 /// Allocates a new `ENCODING_RS_ENCODER` for the given `ENCODING_RS_ENCODING`
287 /// into memory provided by the caller. (In practice, the target should likely
288 /// be a pointer previously returned by `encoding_new_encoder()`.)
289 ///
290 /// # Undefined behavior
291 ///
292 /// UB ensues if either argument is `NULL`.
293 void encoding_new_encoder_into(ENCODING_RS_ENCODING const* encoding,
294 ENCODING_RS_ENCODER* encoder);
295
296 /// Validates UTF-8.
297 ///
298 /// Returns the index of the first byte that makes the input malformed as
299 /// UTF-8 or `buffer_len` if `buffer` is entirely valid.
300 ///
301 /// `buffer` must be non-`NULL` even if `buffer_len` is zero. When
302 /// `buffer_len` is zero, it is OK for `buffer` to be something
303 /// non-dereferencable, such as `0x1`. This is required due to Rust's
304 /// optimization for slices within `Option`.
305 ///
306 /// # Undefined behavior
307 ///
308 /// UB ensues if `buffer` and `buffer_len` don't designate a valid memory
309 /// block of if `buffer` is `NULL`.
310 size_t encoding_utf8_valid_up_to(uint8_t const* buffer, size_t buffer_len);
311
312 /// Validates ASCII.
313 ///
314 /// Returns the index of the first byte that makes the input malformed as
315 /// ASCII or `buffer_len` if `buffer` is entirely valid.
316 ///
317 /// `buffer` must be non-`NULL` even if `buffer_len` is zero. When
318 /// `buffer_len` is zero, it is OK for `buffer` to be something
319 /// non-dereferencable, such as `0x1`. This is required due to Rust's
320 /// optimization for slices within `Option`.
321 ///
322 /// # Undefined behavior
323 ///
324 /// UB ensues if `buffer` and `buffer_len` don't designate a valid memory
325 /// block of if `buffer` is `NULL`.
326 size_t encoding_ascii_valid_up_to(uint8_t const* buffer, size_t buffer_len);
327
328 /// Validates ISO-2022-JP ASCII-state data.
329 ///
330 /// Returns the index of the first byte that makes the input not representable
331 /// in the ASCII state of ISO-2022-JP or `buffer_len` if `buffer` is entirely
332 /// representable in the ASCII state of ISO-2022-JP.
333 ///
334 /// `buffer` must be non-`NULL` even if `buffer_len` is zero. When
335 /// `buffer_len` is zero, it is OK for `buffer` to be something
336 /// non-dereferencable, such as `0x1`. This is required due to Rust's
337 /// optimization for slices within `Option`.
338 ///
339 /// # Undefined behavior
340 ///
341 /// UB ensues if `buffer` and `buffer_len` don't designate a valid memory
342 /// block of if `buffer` is `NULL`.
343 size_t encoding_iso_2022_jp_ascii_valid_up_to(uint8_t const* buffer,
344 size_t buffer_len);
345
346 /// Deallocates a `ENCODING_RS_DECODER` previously allocated by
347 /// `encoding_new_decoder()`.
348 ///
349 /// # Undefined behavior
350 ///
351 /// UB ensues if the argument is `NULL`.
352 void decoder_free(ENCODING_RS_DECODER* decoder);
353
354 /// The `ENCODING_RS_ENCODING` this `ENCODING_RS_DECODER` is for.
355 ///
356 /// BOM sniffing can change the return value of this method during the life
357 /// of the decoder.
358 ///
359 /// # Undefined behavior
360 ///
361 /// UB ensues if the argument is `NULL`.
362 ENCODING_RS_ENCODING const* decoder_encoding(
363 ENCODING_RS_DECODER const* decoder);
364
365 /// Query the worst-case UTF-8 output size _with replacement_.
366 ///
367 /// Returns the size of the output buffer in UTF-8 code units (`uint8_t`)
368 /// that will not overflow given the current state of the decoder and
369 /// `byte_length` number of additional input bytes when decoding with
370 /// errors handled by outputting a REPLACEMENT CHARACTER for each malformed
371 /// sequence or `SIZE_MAX` if `size_t` would overflow.
372 ///
373 /// # Undefined behavior
374 ///
375 /// UB ensues if `decoder` is `NULL`.
376 size_t decoder_max_utf8_buffer_length(ENCODING_RS_DECODER const* decoder,
377 size_t byte_length);
378
379 /// Query the worst-case UTF-8 output size _without replacement_.
380 ///
381 /// Returns the size of the output buffer in UTF-8 code units (`uint8_t`)
382 /// that will not overflow given the current state of the decoder and
383 /// `byte_length` number of additional input bytes when decoding without
384 /// replacement error handling or `SIZE_MAX` if `size_t` would overflow.
385 ///
386 /// Note that this value may be too small for the `_with_replacement` case.
387 /// Use `decoder_max_utf8_buffer_length()` for that case.
388 ///
389 /// # Undefined behavior
390 ///
391 /// UB ensues if `decoder` is `NULL`.
392 size_t decoder_max_utf8_buffer_length_without_replacement(
393 ENCODING_RS_DECODER const* decoder, size_t byte_length);
394
395 /// Incrementally decode a byte stream into UTF-8 with malformed sequences
396 /// replaced with the REPLACEMENT CHARACTER.
397 ///
398 /// See the top-level FFI documentation for documentation for how the
399 /// `decoder_decode_*` functions are mapped from Rust and the documentation
400 /// for the [`ENCODING_RS_DECODER`][1] struct for the semantics.
401 ///
402 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
403 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
404 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
405 /// optimization for slices within `Option`.
406 ///
407 /// # Undefined behavior
408 ///
409 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
410 /// don't designate a valid block of memory or `dst` and `dst_len` don't
411 /// designate a valid block of memory.
412 ///
413 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Decoder.html
414 uint32_t decoder_decode_to_utf8(ENCODING_RS_DECODER* decoder,
415 uint8_t const* src, size_t* src_len,
416 uint8_t* dst, size_t* dst_len, bool last,
417 bool* had_replacements);
418
419 /// Incrementally decode a byte stream into UTF-8 _without replacement_.
420 ///
421 /// See the top-level FFI documentation for documentation for how the
422 /// `decoder_decode_*` functions are mapped from Rust and the documentation
423 /// for the [`ENCODING_RS_DECODER`][1] struct for the semantics.
424 ///
425 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
426 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
427 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
428 /// optimization for slices within `Option`.
429 ///
430 /// # Undefined behavior
431 ///
432 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
433 /// don't designate a valid block of memory or `dst` and `dst_len` don't
434 /// designate a valid block of memory.
435 ///
436 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Decoder.html
437 uint32_t decoder_decode_to_utf8_without_replacement(
438 ENCODING_RS_DECODER* decoder, uint8_t const* src, size_t* src_len,
439 uint8_t* dst, size_t* dst_len, bool last);
440
441 /// Query the worst-case UTF-16 output size (with or without replacement).
442 ///
443 /// Returns the size of the output buffer in UTF-16 code units (`char16_t`)
444 /// that will not overflow given the current state of the decoder and
445 /// `byte_length` number of additional input bytes or `SIZE_MAX` if `size_t`
446 /// would overflow.
447 ///
448 /// Since the REPLACEMENT CHARACTER fits into one UTF-16 code unit, the
449 /// return value of this method applies also in the
450 /// `_without_replacement` case.
451 ///
452 /// # Undefined behavior
453 ///
454 /// UB ensues if `decoder` is `NULL`.
455 size_t decoder_max_utf16_buffer_length(ENCODING_RS_DECODER const* decoder,
456 size_t u16_length);
457
458 /// Incrementally decode a byte stream into UTF-16 with malformed sequences
459 /// replaced with the REPLACEMENT CHARACTER.
460 ///
461 /// See the top-level FFI documentation for documentation for how the
462 /// `decoder_decode_*` functions are mapped from Rust and the documentation
463 /// for the [`ENCODING_RS_DECODER`][1] struct for the semantics.
464 ///
465 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
466 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
467 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
468 /// optimization for slices within `Option`.
469 ///
470 /// # Undefined behavior
471 ///
472 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
473 /// don't designate a valid block of memory or `dst` and `dst_len` don't
474 /// designate a valid block of memory.
475 ///
476 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Decoder.html
477 uint32_t decoder_decode_to_utf16(ENCODING_RS_DECODER* decoder,
478 uint8_t const* src, size_t* src_len,
479 char16_t* dst, size_t* dst_len, bool last,
480 bool* had_replacements);
481
482 /// Incrementally decode a byte stream into UTF-16 _without replacement_.
483 ///
484 /// See the top-level FFI documentation for documentation for how the
485 /// `decoder_decode_*` functions are mapped from Rust and the documentation
486 /// for the [`ENCODING_RS_DECODER`][1] struct for the semantics.
487 ///
488 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
489 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
490 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
491 /// optimization for slices within `Option`.
492 ///
493 /// # Undefined behavior
494 ///
495 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
496 /// don't designate a valid block of memory or `dst` and `dst_len` don't
497 /// designate a valid block of memory.
498 ///
499 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Decoder.html
500 uint32_t decoder_decode_to_utf16_without_replacement(
501 ENCODING_RS_DECODER* decoder, uint8_t const* src, size_t* src_len,
502 char16_t* dst, size_t* dst_len, bool last);
503
504 /// Checks for compatibility with storing Unicode scalar values as unsigned
505 /// bytes taking into account the state of the decoder.
506 ///
507 /// Returns `SIZE_MAX` if the decoder is not in a neutral state, including waiting
508 /// for the BOM, or if the encoding is never Latin1-byte-compatible.
509 ///
510 /// Otherwise returns the index of the first byte whose unsigned value doesn't
511 /// directly correspond to the decoded Unicode scalar value, or the length
512 /// of the input if all bytes in the input decode directly to scalar values
513 /// corresponding to the unsigned byte values.
514 ///
515 /// Does not change the state of the decoder.
516 ///
517 /// Do not use this unless you are supporting SpiderMonkey/V8-style string
518 /// storage optimizations.
519 ///
520 /// # Undefined behavior
521 ///
522 /// UB ensues if `buffer` and `*buffer_len` don't designate a valid memory
523 /// block of if `buffer` is `NULL`.
524 size_t decoder_latin1_byte_compatible_up_to(ENCODING_RS_DECODER const* decoder,
525 uint8_t const* buffer,
526 size_t buffer_len);
527
528 /// Deallocates an `ENCODING_RS_ENCODER` previously allocated by
529 /// `encoding_new_encoder()`.
530 ///
531 /// # Undefined behavior
532 ///
533 /// UB ensues if the argument is `NULL`.
534 void encoder_free(ENCODING_RS_ENCODER* encoder);
535
536 /// The `ENCODING_RS_ENCODING` this `ENCODING_RS_ENCODER` is for.
537 ///
538 /// # Undefined behavior
539 ///
540 /// UB ensues if the argument is `NULL`.
541 ENCODING_RS_ENCODING const* encoder_encoding(
542 ENCODING_RS_ENCODER const* encoder);
543
544 /// Returns `true` if this is an ISO-2022-JP encoder that's not in the
545 /// ASCII state and `false` otherwise.
546 ///
547 /// # Undefined behavior
548 ///
549 /// UB ensues if the argument is `NULL`.
550 bool encoder_has_pending_state(ENCODING_RS_ENCODER const* encoder);
551
552 /// Query the worst-case output size when encoding from UTF-8 with
553 /// replacement.
554 ///
555 /// Returns the size of the output buffer in bytes that will not overflow
556 /// given the current state of the encoder and `byte_length` number of
557 /// additional input code units if there are no unmappable characters in
558 /// the input or `SIZE_MAX` if `size_t` would overflow.
559 size_t encoder_max_buffer_length_from_utf8_if_no_unmappables(
560 ENCODING_RS_ENCODER const* encoder, size_t byte_length);
561
562 /// Query the worst-case output size when encoding from UTF-8 without
563 /// replacement.
564 ///
565 /// Returns the size of the output buffer in bytes that will not overflow
566 /// given the current state of the encoder and `byte_length` number of
567 /// additional input code units or `SIZE_MAX` if `size_t` would overflow.
568 size_t encoder_max_buffer_length_from_utf8_without_replacement(
569 ENCODING_RS_ENCODER const* encoder, size_t byte_length);
570
571 /// Incrementally encode into byte stream from UTF-8 with unmappable
572 /// characters replaced with HTML (decimal) numeric character references.
573 ///
574 /// The input absolutely _MUST_ be valid UTF-8 or the behavior is memory-unsafe!
575 /// If in doubt, check the validity of input before using!
576 ///
577 /// See the top-level FFI documentation for documentation for how the
578 /// `encoder_encode_*` functions are mapped from Rust and the documentation
579 /// for the [`ENCODING_RS_ENCODER`][1] struct for the semantics.
580 ///
581 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
582 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
583 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
584 /// optimization for slices within `Option`.
585 ///
586 /// # Undefined behavior
587 ///
588 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
589 /// don't designate a valid block of memory or `dst` and `dst_len` don't
590 /// designate a valid block of memory.
591 ///
592 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Encoder.html
593 uint32_t encoder_encode_from_utf8(ENCODING_RS_ENCODER* encoder,
594 uint8_t const* src, size_t* src_len,
595 uint8_t* dst, size_t* dst_len, bool last,
596 bool* had_replacements);
597
598 /// Incrementally encode into byte stream from UTF-8 _without replacement_.
599 ///
600 /// See the top-level FFI documentation for documentation for how the
601 /// `encoder_encode_*` functions are mapped from Rust and the documentation
602 /// for the [`ENCODING_RS_ENCODER`][1] struct for the semantics.
603 ///
604 /// The input absolutely _MUST_ be valid UTF-8 or the behavior is memory-unsafe!
605 /// If in doubt, check the validity of input before using!
606 ///
607 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
608 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
609 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
610 /// optimization for slices within `Option`.
611 ///
612 /// # Undefined behavior
613 ///
614 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
615 /// don't designate a valid block of memory or `dst` and `dst_len` don't
616 /// designate a valid block of memory.
617 ///
618 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Encoder.html
619 uint32_t encoder_encode_from_utf8_without_replacement(
620 ENCODING_RS_ENCODER* encoder, uint8_t const* src, size_t* src_len,
621 uint8_t* dst, size_t* dst_len, bool last);
622
623 /// Query the worst-case output size when encoding from UTF-16 with
624 /// replacement.
625 ///
626 /// Returns the size of the output buffer in bytes that will not overflow
627 /// given the current state of the encoder and `u16_length` number of
628 /// additional input code units if there are no unmappable characters in
629 /// the input or `SIZE_MAX` if `size_t` would overflow.
630 size_t encoder_max_buffer_length_from_utf16_if_no_unmappables(
631 ENCODING_RS_ENCODER const* encoder, size_t u16_length);
632
633 /// Query the worst-case output size when encoding from UTF-16 without
634 /// replacement.
635 ///
636 /// Returns the size of the output buffer in bytes that will not overflow
637 /// given the current state of the encoder and `u16_length` number of
638 /// additional input code units or `SIZE_MAX` if `size_t` would overflow.
639 size_t encoder_max_buffer_length_from_utf16_without_replacement(
640 ENCODING_RS_ENCODER const* encoder, size_t u16_length);
641
642 /// Incrementally encode into byte stream from UTF-16 with unmappable
643 /// characters replaced with HTML (decimal) numeric character references.
644 ///
645 /// See the top-level FFI documentation for documentation for how the
646 /// `encoder_encode_*` functions are mapped from Rust and the documentation
647 /// for the [`ENCODING_RS_ENCODER`][1] struct for the semantics.
648 ///
649 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
650 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
651 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
652 /// optimization for slices within `Option`.
653 ///
654 /// # Undefined behavior
655 ///
656 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
657 /// don't designate a valid block of memory or `dst` and `dst_len` don't
658 /// designate a valid block of memory.
659 ///
660 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Encoder.html
661 uint32_t encoder_encode_from_utf16(ENCODING_RS_ENCODER* encoder,
662 char16_t const* src, size_t* src_len,
663 uint8_t* dst, size_t* dst_len, bool last,
664 bool* had_replacements);
665
666 /// Incrementally encode into byte stream from UTF-16 _without replacement_.
667 ///
668 /// See the top-level FFI documentation for documentation for how the
669 /// `encoder_encode_*` functions are mapped from Rust and the documentation
670 /// for the [`ENCODING_RS_ENCODER`][1] struct for the semantics.
671 ///
672 /// `src` must be non-`NULL` even if `src_len` is zero. When`src_len` is zero,
673 /// it is OK for `src` to be something non-dereferencable, such as `0x1`.
674 /// Likewise for `dst` when `dst_len` is zero. This is required due to Rust's
675 /// optimization for slices within `Option`.
676 ///
677 /// # Undefined behavior
678 ///
679 /// UB ensues if any of the pointer arguments is `NULL`, `src` and `src_len`
680 /// don't designate a valid block of memory or `dst` and `dst_len` don't
681 /// designate a valid block of memory.
682 ///
683 /// [1]: https://docs.rs/encoding_rs/0.6.10/encoding_rs/struct.Encoder.html
684 uint32_t encoder_encode_from_utf16_without_replacement(
685 ENCODING_RS_ENCODER* encoder, char16_t const* src, size_t* src_len,
686 uint8_t* dst, size_t* dst_len, bool last);
687
688 #ifdef __cplusplus
689 }
690 #endif
691
692 #endif