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