| 1 | # encoding_rs |
| 2 | |
| 3 | [](https://travis-ci.org/hsivonen/encoding_rs) |
| 4 | [](https://crates.io/crates/encoding_rs) |
| 5 | [](https://docs.rs/encoding_rs/) |
| 6 | |
| 7 | encoding_rs an implementation of the (non-JavaScript parts of) the |
| 8 | [Encoding Standard](https://encoding.spec.whatwg.org/) written in Rust. |
| 9 | |
| 10 | The Encoding Standard defines the Web-compatible set of character encodings, |
| 11 | which means this crate can be used to decode Web content. encoding_rs is |
| 12 | used in Gecko starting with Firefox 56. Due to the notable overlap between |
| 13 | the legacy encodings on the Web and the legacy encodings used on Windows, |
| 14 | this crate may be of use for non-Web-related situations as well; see below |
| 15 | for links to adjacent crates. |
| 16 | |
| 17 | Additionally, the `mem` module provides various operations for dealing with |
| 18 | in-RAM text (as opposed to data that's coming from or going to an IO boundary). |
| 19 | The `mem` module is a module instead of a separate crate due to internal |
| 20 | implementation detail efficiencies. |
| 21 | |
| 22 | ## Functionality |
| 23 | |
| 24 | Due to the Gecko use case, encoding_rs supports decoding to and encoding from |
| 25 | UTF-16 in addition to supporting the usual Rust use case of decoding to and |
| 26 | encoding from UTF-8. Additionally, the API has been designed to be FFI-friendly |
| 27 | to accommodate the C++ side of Gecko. |
| 28 | |
| 29 | Specifically, encoding_rs does the following: |
| 30 | |
| 31 | * Decodes a stream of bytes in an Encoding Standard-defined character encoding |
| 32 | into valid aligned native-endian in-RAM UTF-16 (units of `u16` / `char16_t`). |
| 33 | * Encodes a stream of potentially-invalid aligned native-endian in-RAM UTF-16 |
| 34 | (units of `u16` / `char16_t`) into a sequence of bytes in an Encoding |
| 35 | Standard-defined character encoding as if the lone surrogates had been |
| 36 | replaced with the REPLACEMENT CHARACTER before performing the encode. |
| 37 | (Gecko's UTF-16 is potentially invalid.) |
| 38 | * Decodes a stream of bytes in an Encoding Standard-defined character |
| 39 | encoding into valid UTF-8. |
| 40 | * Encodes a stream of valid UTF-8 into a sequence of bytes in an Encoding |
| 41 | Standard-defined character encoding. (Rust's UTF-8 is guaranteed-valid.) |
| 42 | * Does the above in streaming (input and output split across multiple |
| 43 | buffers) and non-streaming (whole input in a single buffer and whole |
| 44 | output in a single buffer) variants. |
| 45 | * Avoids copying (borrows) when possible in the non-streaming cases when |
| 46 | decoding to or encoding from UTF-8. |
| 47 | * Resolves textual labels that identify character encodings in |
| 48 | protocol text into type-safe objects representing the those encodings |
| 49 | conceptually. |
| 50 | * Maps the type-safe encoding objects onto strings suitable for |
| 51 | returning from `document.characterSet`. |
| 52 | * Validates UTF-8 (in common instruction set scenarios a bit faster for Web |
| 53 | workloads than the standard library; hopefully will get upstreamed some |
| 54 | day) and ASCII. |
| 55 | |
| 56 | Additionally, `encoding_rs::mem` does the following: |
| 57 | |
| 58 | * Checks if a byte buffer contains only ASCII. |
| 59 | * Checks if a potentially-invalid UTF-16 buffer contains only Basic Latin (ASCII). |
| 60 | * Checks if a valid UTF-8, potentially-invalid UTF-8 or potentially-invalid UTF-16 |
| 61 | buffer contains only Latin1 code points (below U+0100). |
| 62 | * Checks if a valid UTF-8, potentially-invalid UTF-8 or potentially-invalid UTF-16 |
| 63 | buffer or a code point or a UTF-16 code unit can trigger right-to-left behavior |
| 64 | (suitable for checking if the Unicode Bidirectional Algorithm can be optimized |
| 65 | out). |
| 66 | * Combined versions of the above two checks. |
| 67 | * Converts valid UTF-8, potentially-invalid UTF-8 and Latin1 to UTF-16. |
| 68 | * Converts potentially-invalid UTF-16 and Latin1 to UTF-8. |
| 69 | * Converts UTF-8 and UTF-16 to Latin1 (if in range). |
| 70 | * Finds the first invalid code unit in a buffer of potentially-invalid UTF-16. |
| 71 | * Makes a mutable buffer of potential-invalid UTF-16 contain valid UTF-16. |
| 72 | * Copies ASCII from one buffer to another up to the first non-ASCII byte. |
| 73 | * Converts ASCII to UTF-16 up to the first non-ASCII byte. |
| 74 | * Converts UTF-16 to ASCII up to the first non-Basic Latin code unit. |
| 75 | |
| 76 | ## Integration with `std::io` |
| 77 | |
| 78 | Notably, the above feature list doesn't include the capability to wrap |
| 79 | a `std::io::Read`, decode it into UTF-8 and presenting the result via |
| 80 | `std::io::Read`. The [`encoding_rs_io`](https://crates.io/crates/encoding_rs_io) |
| 81 | crate provides that capability. |
| 82 | |
| 83 | ## `no_std` Environment |
| 84 | |
| 85 | The crate works in a `no_std` environment. By default, the `alloc` feature, |
| 86 | which assumes that an allocator is present is enabled. For a no-allocator |
| 87 | environment, the default features (i.e. `alloc`) can be turned off. This |
| 88 | makes the part of the API that returns `Vec`/`String`/`Cow` unavailable. |
| 89 | |
| 90 | ## Decoding Email |
| 91 | |
| 92 | For decoding character encodings that occur in email, use the |
| 93 | [`charset`](https://crates.io/crates/charset) crate instead of using this |
| 94 | one directly. (It wraps this crate and adds UTF-7 decoding.) |
| 95 | |
| 96 | ## Windows Code Page Identifier Mappings |
| 97 | |
| 98 | For mappings to and from Windows code page identifiers, use the |
| 99 | [`codepage`](https://crates.io/crates/codepage) crate. |
| 100 | |
| 101 | ## DOS Encodings |
| 102 | |
| 103 | This crate does not support single-byte DOS encodings that aren't required by |
| 104 | the Web Platform, but the [`oem_cp`](https://crates.io/crates/oem_cp) crate does. |
| 105 | |
| 106 | ## Preparing Text for the Encoders |
| 107 | |
| 108 | Normalizing text into Unicode Normalization Form C prior to encoding text into |
| 109 | a legacy encoding minimizes unmappable characters. Text can be normalized to |
| 110 | Unicode Normalization Form C using the |
| 111 | [`icu_normalizer`](https://crates.io/crates/icu_normalizer) crate. |
| 112 | |
| 113 | The exception is windows-1258, which after normalizing to Unicode Normalization |
| 114 | Form C requires tone marks to be decomposed in order to minimize unmappable |
| 115 | characters. Vietnamese tone marks can be decomposed using the |
| 116 | [`detone`](https://crates.io/crates/detone) crate. |
| 117 | |
| 118 | ## Licensing |
| 119 | |
| 120 | TL;DR: `(Apache-2.0 OR MIT) AND BSD-3-Clause` for the code and data combination. |
| 121 | |
| 122 | Please see the file named |
| 123 | [COPYRIGHT](https://github.com/hsivonen/encoding_rs/blob/master/COPYRIGHT). |
| 124 | |
| 125 | The non-test code that isn't generated from the WHATWG data in this crate is |
| 126 | under Apache-2.0 OR MIT. Test code is under CC0. |
| 127 | |
| 128 | This crate contains code/data generated from WHATWG-supplied data. The WHATWG |
| 129 | upstream changed its license for portions of specs incorporated into source code |
| 130 | from CC0 to BSD-3-Clause between the initial release of this crate and the present |
| 131 | version of this crate. The in-source licensing legends have been updated for the |
| 132 | parts of the generated code that have changed since the upstream license change. |
| 133 | |
| 134 | ## Documentation |
| 135 | |
| 136 | Generated [API documentation](https://docs.rs/encoding_rs/) is available |
| 137 | online. |
| 138 | |
| 139 | There is a [long-form write-up](https://hsivonen.fi/encoding_rs/) about the |
| 140 | design and internals of the crate. |
| 141 | |
| 142 | ## C and C++ bindings |
| 143 | |
| 144 | An FFI layer for encoding_rs is available as a |
| 145 | [separate crate](https://github.com/hsivonen/encoding_c). The crate comes |
| 146 | with a [demo C++ wrapper](https://github.com/hsivonen/encoding_c/blob/master/include/encoding_rs_cpp.h) |
| 147 | using the C++ standard library and [GSL](https://github.com/Microsoft/GSL/) types. |
| 148 | |
| 149 | The bindings for the `mem` module are in the |
| 150 | [encoding_c_mem crate](https://github.com/hsivonen/encoding_c_mem). |
| 151 | |
| 152 | For the Gecko context, there's a |
| 153 | [C++ wrapper using the MFBT/XPCOM types](https://searchfox.org/mozilla-central/source/intl/Encoding.h#100). |
| 154 | |
| 155 | There's a [write-up](https://hsivonen.fi/modern-cpp-in-rust/) about the C++ |
| 156 | wrappers. |
| 157 | |
| 158 | ## Sample programs |
| 159 | |
| 160 | * [Rust](https://github.com/hsivonen/recode_rs) |
| 161 | * [C](https://github.com/hsivonen/recode_c) |
| 162 | * [C++](https://github.com/hsivonen/recode_cpp) |
| 163 | |
| 164 | ## Optional features |
| 165 | |
| 166 | There are currently these optional cargo features: |
| 167 | |
| 168 | ### `simd-accel` |
| 169 | |
| 170 | Enables SIMD acceleration using the nightly-dependent `portable_simd` standard |
| 171 | library feature. |
| 172 | |
| 173 | This is an opt-in feature, because enabling this feature _opts out_ of Rust's |
| 174 | guarantees of future compilers compiling old code (aka. "stability story"). |
| 175 | |
| 176 | Currently, this has not been tested to be an improvement except for these |
| 177 | targets and enabling the `simd-accel` feature is expected to break the build |
| 178 | on other targets: |
| 179 | |
| 180 | * x86_64 |
| 181 | * i686 |
| 182 | * aarch64 |
| 183 | * thumbv7neon |
| 184 | |
| 185 | If you use nightly Rust, you use targets whose first component is one of the |
| 186 | above, and you are prepared _to have to revise your configuration when updating |
| 187 | Rust_, you should enable this feature. Otherwise, please _do not_ enable this |
| 188 | feature. |
| 189 | |
| 190 | Used by Firefox. |
| 191 | |
| 192 | ### `serde` |
| 193 | |
| 194 | Enables support for serializing and deserializing `&'static Encoding`-typed |
| 195 | struct fields using [Serde][1]. |
| 196 | |
| 197 | [1]: https://serde.rs/ |
| 198 | |
| 199 | Not used by Firefox. |
| 200 | |
| 201 | ### `fast-legacy-encode` |
| 202 | |
| 203 | A catch-all option for enabling the fastest legacy encode options. _Does not |
| 204 | affect decode speed or UTF-8 encode speed._ |
| 205 | |
| 206 | At present, this option is equivalent to enabling the following options: |
| 207 | * `fast-hangul-encode` |
| 208 | * `fast-hanja-encode` |
| 209 | * `fast-kanji-encode` |
| 210 | * `fast-gb-hanzi-encode` |
| 211 | * `fast-big5-hanzi-encode` |
| 212 | |
| 213 | Adds 176 KB to the binary size. |
| 214 | |
| 215 | Not used by Firefox. |
| 216 | |
| 217 | ### `fast-hangul-encode` |
| 218 | |
| 219 | Changes encoding precomposed Hangul syllables into EUC-KR from binary |
| 220 | search over the decode-optimized tables to lookup by index making Korean |
| 221 | plain-text encode about 4 times as fast as without this option. |
| 222 | |
| 223 | Adds 20 KB to the binary size. |
| 224 | |
| 225 | Does _not_ affect decode speed. |
| 226 | |
| 227 | Not used by Firefox. |
| 228 | |
| 229 | ### `fast-hanja-encode` |
| 230 | |
| 231 | Changes encoding of Hanja into EUC-KR from linear search over the |
| 232 | decode-optimized table to lookup by index. Since Hanja is practically absent |
| 233 | in modern Korean text, this option doesn't affect perfomance in the common |
| 234 | case and mainly makes sense if you want to make your application resilient |
| 235 | agaist denial of service by someone intentionally feeding it a lot of Hanja |
| 236 | to encode into EUC-KR. |
| 237 | |
| 238 | Adds 40 KB to the binary size. |
| 239 | |
| 240 | Does _not_ affect decode speed. |
| 241 | |
| 242 | Not used by Firefox. |
| 243 | |
| 244 | ### `fast-kanji-encode` |
| 245 | |
| 246 | Changes encoding of Kanji into Shift_JIS, EUC-JP and ISO-2022-JP from linear |
| 247 | search over the decode-optimized tables to lookup by index making Japanese |
| 248 | plain-text encode to legacy encodings 30 to 50 times as fast as without this |
| 249 | option (about 2 times as fast as with `less-slow-kanji-encode`). |
| 250 | |
| 251 | Takes precedence over `less-slow-kanji-encode`. |
| 252 | |
| 253 | Adds 36 KB to the binary size (24 KB compared to `less-slow-kanji-encode`). |
| 254 | |
| 255 | Does _not_ affect decode speed. |
| 256 | |
| 257 | Not used by Firefox. |
| 258 | |
| 259 | ### `less-slow-kanji-encode` |
| 260 | |
| 261 | Makes JIS X 0208 Level 1 Kanji (the most common Kanji in Shift_JIS, EUC-JP and |
| 262 | ISO-2022-JP) encode less slow (binary search instead of linear search) making |
| 263 | Japanese plain-text encode to legacy encodings 14 to 23 times as fast as |
| 264 | without this option. |
| 265 | |
| 266 | Adds 12 KB to the binary size. |
| 267 | |
| 268 | Does _not_ affect decode speed. |
| 269 | |
| 270 | Not used by Firefox. |
| 271 | |
| 272 | ### `fast-gb-hanzi-encode` |
| 273 | |
| 274 | Changes encoding of Hanzi in the CJK Unified Ideographs block into GBK and |
| 275 | gb18030 from linear search over a part the decode-optimized tables followed |
| 276 | by a binary search over another part of the decode-optimized tables to lookup |
| 277 | by index making Simplified Chinese plain-text encode to the legacy encodings |
| 278 | 100 to 110 times as fast as without this option (about 2.5 times as fast as |
| 279 | with `less-slow-gb-hanzi-encode`). |
| 280 | |
| 281 | Takes precedence over `less-slow-gb-hanzi-encode`. |
| 282 | |
| 283 | Adds 36 KB to the binary size (24 KB compared to `less-slow-gb-hanzi-encode`). |
| 284 | |
| 285 | Does _not_ affect decode speed. |
| 286 | |
| 287 | Not used by Firefox. |
| 288 | |
| 289 | ### `less-slow-gb-hanzi-encode` |
| 290 | |
| 291 | Makes GB2312 Level 1 Hanzi (the most common Hanzi in gb18030 and GBK) encode |
| 292 | less slow (binary search instead of linear search) making Simplified Chinese |
| 293 | plain-text encode to the legacy encodings about 40 times as fast as without |
| 294 | this option. |
| 295 | |
| 296 | Adds 12 KB to the binary size. |
| 297 | |
| 298 | Does _not_ affect decode speed. |
| 299 | |
| 300 | Not used by Firefox. |
| 301 | |
| 302 | ### `fast-big5-hanzi-encode` |
| 303 | |
| 304 | Changes encoding of Hanzi in the CJK Unified Ideographs block into Big5 from |
| 305 | linear search over a part the decode-optimized tables to lookup by index |
| 306 | making Traditional Chinese plain-text encode to Big5 105 to 125 times as fast |
| 307 | as without this option (about 3 times as fast as with |
| 308 | `less-slow-big5-hanzi-encode`). |
| 309 | |
| 310 | Takes precedence over `less-slow-big5-hanzi-encode`. |
| 311 | |
| 312 | Adds 40 KB to the binary size (20 KB compared to `less-slow-big5-hanzi-encode`). |
| 313 | |
| 314 | Does _not_ affect decode speed. |
| 315 | |
| 316 | Not used by Firefox. |
| 317 | |
| 318 | ### `less-slow-big5-hanzi-encode` |
| 319 | |
| 320 | Makes Big5 Level 1 Hanzi (the most common Hanzi in Big5) encode less slow |
| 321 | (binary search instead of linear search) making Traditional Chinese |
| 322 | plain-text encode to Big5 about 36 times as fast as without this option. |
| 323 | |
| 324 | Adds 20 KB to the binary size. |
| 325 | |
| 326 | Does _not_ affect decode speed. |
| 327 | |
| 328 | Not used by Firefox. |
| 329 | |
| 330 | ## Performance goals |
| 331 | |
| 332 | For decoding to UTF-16, the goal is to perform at least as well as Gecko's old |
| 333 | uconv. For decoding to UTF-8, the goal is to perform at least as well as |
| 334 | rust-encoding. These goals have been achieved. |
| 335 | |
| 336 | Encoding to UTF-8 should be fast. (UTF-8 to UTF-8 encode should be equivalent |
| 337 | to `memcpy` and UTF-16 to UTF-8 should be fast.) |
| 338 | |
| 339 | Speed is a non-goal when encoding to legacy encodings. By default, encoding to |
| 340 | legacy encodings should not be optimized for speed at the expense of code size |
| 341 | as long as form submission and URL parsing in Gecko don't become noticeably |
| 342 | too slow in real-world use. |
| 343 | |
| 344 | In the interest of binary size, by default, encoding_rs does not have |
| 345 | encode-specific data tables beyond 32 bits of encode-specific data for each |
| 346 | single-byte encoding. Therefore, encoders search the decode-optimized data |
| 347 | tables. This is a linear search in most cases. As a result, by default, encode |
| 348 | to legacy encodings varies from slow to extremely slow relative to other |
| 349 | libraries. Still, with realistic work loads, this seemed fast enough not to be |
| 350 | user-visibly slow on Raspberry Pi 3 (which stood in for a phone for testing) |
| 351 | in the Web-exposed encoder use cases. |
| 352 | |
| 353 | See the cargo features above for optionally making CJK legacy encode fast. |
| 354 | |
| 355 | A framework for measuring performance is [available separately][2]. |
| 356 | |
| 357 | [2]: https://github.com/hsivonen/encoding_bench/ |
| 358 | |
| 359 | ## Rust Version Compatibility |
| 360 | |
| 361 | It is a goal to support the latest stable Rust, the latest nightly Rust and |
| 362 | the version of Rust that's used for Firefox Nightly. |
| 363 | |
| 364 | At this time, there is no firm commitment to support a version older than |
| 365 | what's required by Firefox, and there is no commitment to treat MSRV changes |
| 366 | as semver-breaking, because this crate depends on `cfg-if`, which doesn't |
| 367 | appear to treat MSRV changes as semver-breaking, so it would be useless for |
| 368 | this crate to treat MSRV changes as semver-breaking. |
| 369 | |
| 370 | As of 2024-04-04, MSRV appears to be Rust 1.36.0 for using the crate and |
| 371 | 1.42.0 for doc tests to pass without errors about the global allocator. |
| 372 | With the `simd-accel` feature, the MSRV is even higher. |
| 373 | |
| 374 | ## Compatibility with rust-encoding |
| 375 | |
| 376 | A compatibility layer that implements the rust-encoding API on top of |
| 377 | encoding_rs is |
| 378 | [provided as a separate crate](https://github.com/hsivonen/encoding_rs_compat) |
| 379 | (cannot be uploaded to crates.io). The compatibility layer was originally |
| 380 | written with the assuption that Firefox would need it, but it is not currently |
| 381 | used in Firefox. |
| 382 | |
| 383 | ## Regenerating Generated Code |
| 384 | |
| 385 | To regenerate the generated code: |
| 386 | |
| 387 | * Have Python 2 installed. |
| 388 | * Clone [`https://github.com/hsivonen/encoding_c`](https://github.com/hsivonen/encoding_c) |
| 389 | next to the `encoding_rs` directory. |
| 390 | * Clone [`https://github.com/hsivonen/codepage`](https://github.com/hsivonen/codepage) |
| 391 | next to the `encoding_rs` directory. |
| 392 | * Clone [`https://github.com/whatwg/encoding`](https://github.com/whatwg/encoding) |
| 393 | next to the `encoding_rs` directory. |
| 394 | * Checkout revision `1d519bf8e5555cef64cf3a712485f41cd1a6a990` of the `encoding` repo. |
| 395 | (Note: `f381389` was the revision of `encoding` used from before the `encoding` repo |
| 396 | license change.) |
| 397 | * With the `encoding_rs` directory as the working directory, run |
| 398 | `python generate-encoding-data.py`. |
| 399 | |
| 400 | ## Roadmap |
| 401 | |
| 402 | - [x] Design the low-level API. |
| 403 | - [x] Provide Rust-only convenience features. |
| 404 | - [x] Provide an stl/gsl-flavored C++ API. |
| 405 | - [x] Implement all decoders and encoders. |
| 406 | - [x] Add unit tests for all decoders and encoders. |
| 407 | - [x] Finish BOM sniffing variants in Rust-only convenience features. |
| 408 | - [x] Document the API. |
| 409 | - [x] Publish the crate on crates.io. |
| 410 | - [x] Create a solution for measuring performance. |
| 411 | - [x] Accelerate ASCII conversions using SSE2 on x86. |
| 412 | - [x] Accelerate ASCII conversions using ALU register-sized operations on |
| 413 | non-x86 architectures (process an `usize` instead of `u8` at a time). |
| 414 | - [x] Split FFI into a separate crate so that the FFI doesn't interfere with |
| 415 | LTO in pure-Rust usage. |
| 416 | - [x] Compress CJK indices by making use of sequential code points as well |
| 417 | as Unicode-ordered parts of indices. |
| 418 | - [x] Make lookups by label or name use binary search that searches from the |
| 419 | end of the label/name to the start. |
| 420 | - [x] Make labels with non-ASCII bytes fail fast. |
| 421 | - [ ] ~Parallelize UTF-8 validation using [Rayon](https://github.com/nikomatsakis/rayon).~ |
| 422 | (This turned out to be a pessimization in the ASCII case due to memory bandwidth reasons.) |
| 423 | - [x] Provide an XPCOM/MFBT-flavored C++ API. |
| 424 | - [x] Investigate accelerating single-byte encode with a single fast-tracked |
| 425 | range per encoding. |
| 426 | - [x] Replace uconv with encoding_rs in Gecko. |
| 427 | - [x] Implement the rust-encoding API in terms of encoding_rs. |
| 428 | - [x] Add SIMD acceleration for Aarch64. |
| 429 | - [x] Investigate the use of NEON on 32-bit ARM. |
| 430 | - [ ] ~Investigate Björn Höhrmann's lookup table acceleration for UTF-8 as |
| 431 | adapted to Rust in rust-encoding.~ |
| 432 | - [x] Add actually fast CJK encode options. |
| 433 | - [ ] ~Investigate [Bob Steagall's lookup table acceleration for UTF-8](https://github.com/BobSteagall/CppNow2018/blob/master/FastConversionFromUTF-8/Fast%20Conversion%20From%20UTF-8%20with%20C%2B%2B%2C%20DFAs%2C%20and%20SSE%20Intrinsics%20-%20Bob%20Steagall%20-%20C%2B%2BNow%202018.pdf).~ |
| 434 | - [x] Provide a build mode that works without `alloc` (with lesser API surface). |
| 435 | - [x] Migrate to `std::simd` ~once it is stable and declare 1.0.~ |
| 436 | - [ ] Migrate `unsafe` slice access by larger types than `u8`/`u16` to `align_to`. |
| 437 | |
| 438 | ## Release Notes |
| 439 | |
| 440 | ### 0.8.35 |
| 441 | |
| 442 | * Implement changes for GB18030-2022. (Intentionally not treated as a semver break in practice even if this could be argued to be a breaking change in theory.) |
| 443 | |
| 444 | ### 0.8.34 |
| 445 | |
| 446 | * Use the `portable_simd` nightly feature of the standard library instead of the `packed_simd` crate. Only affects the `simd-accel` optional nightly feature. |
| 447 | * Internal documentation improvements and minor code improvements around `unsafe`. |
| 448 | * Added `rust-version` to `Cargo.toml`. |
| 449 | |
| 450 | ### 0.8.33 |
| 451 | |
| 452 | * Use `packed_simd` instead of `packed_simd_2` again now that updates are back under the `packed_simd` name. Only affects the `simd-accel` optional nightly feature. |
| 453 | |
| 454 | ### 0.8.32 |
| 455 | |
| 456 | * Removed `build.rs`. (This removal should resolve false positives reported by some antivirus products. This may break some build configurations that have opted out of Rust's guarantees against future build breakage.) |
| 457 | * Internal change to what API is used for reinterpreting the lane configuration of SIMD vectors. |
| 458 | * Documentation improvements. |
| 459 | |
| 460 | ### 0.8.31 |
| 461 | |
| 462 | * Use SPDX with parentheses now that crates.io supports parentheses. |
| 463 | |
| 464 | ### 0.8.30 |
| 465 | |
| 466 | * Update the licensing information to take into account the WHATWG data license change. |
| 467 | |
| 468 | ### 0.8.29 |
| 469 | |
| 470 | * Make the parts that use an allocator optional. |
| 471 | |
| 472 | ### 0.8.28 |
| 473 | |
| 474 | * Fix error in Serde support introduced as part of `no_std` support. |
| 475 | |
| 476 | ### 0.8.27 |
| 477 | |
| 478 | * Make the crate works in a `no_std` environment (with `alloc`). |
| 479 | |
| 480 | ### 0.8.26 |
| 481 | |
| 482 | * Fix oversights in edition 2018 migration that broke the `simd-accel` feature. |
| 483 | |
| 484 | ### 0.8.25 |
| 485 | |
| 486 | * Do pointer alignment checks in a way where intermediate steps aren't defined to be Undefined Behavior. |
| 487 | * Update the `packed_simd` dependency to `packed_simd_2`. |
| 488 | * Update the `cfg-if` dependency to 1.0. |
| 489 | * Address warnings that have been introduced by newer Rust versions along the way. |
| 490 | * Update to edition 2018, since even prior to 1.0 `cfg-if` updated to edition 2018 without a semver break. |
| 491 | |
| 492 | ### 0.8.24 |
| 493 | |
| 494 | * Avoid computing an intermediate (not dereferenced) pointer value in a manner designated as Undefined Behavior when computing pointer alignment. |
| 495 | |
| 496 | ### 0.8.23 |
| 497 | |
| 498 | * Remove year from copyright notices. (No features or bug fixes.) |
| 499 | |
| 500 | ### 0.8.22 |
| 501 | |
| 502 | * Formatting fix and new unit test. (No features or bug fixes.) |
| 503 | |
| 504 | ### 0.8.21 |
| 505 | |
| 506 | * Fixed a panic with invalid UTF-16[BE|LE] input at the end of the stream. |
| 507 | |
| 508 | ### 0.8.20 |
| 509 | |
| 510 | * Make `Decoder::latin1_byte_compatible_up_to` return `None` in more |
| 511 | cases to make the method actually useful. While this could be argued |
| 512 | to be a breaking change due to the bug fix changing semantics, it does |
| 513 | not break callers that had to handle the `None` case in a reasonable |
| 514 | way anyway. |
| 515 | |
| 516 | ### 0.8.19 |
| 517 | |
| 518 | * Removed a bunch of bound checks in `convert_str_to_utf16`. |
| 519 | * Added `mem::convert_utf8_to_utf16_without_replacement`. |
| 520 | |
| 521 | ### 0.8.18 |
| 522 | |
| 523 | * Added `mem::utf8_latin1_up_to` and `mem::str_latin1_up_to`. |
| 524 | * Added `Decoder::latin1_byte_compatible_up_to`. |
| 525 | |
| 526 | ### 0.8.17 |
| 527 | |
| 528 | * Update `bincode` (dev dependency) version requirement to 1.0. |
| 529 | |
| 530 | ### 0.8.16 |
| 531 | |
| 532 | * Switch from the `simd` crate to `packed_simd`. |
| 533 | |
| 534 | ### 0.8.15 |
| 535 | |
| 536 | * Adjust documentation for `simd-accel` (README-only release). |
| 537 | |
| 538 | ### 0.8.14 |
| 539 | |
| 540 | * Made UTF-16 to UTF-8 encode conversion fill the output buffer as |
| 541 | closely as possible. |
| 542 | |
| 543 | ### 0.8.13 |
| 544 | |
| 545 | * Made the UTF-8 to UTF-16 decoder compare the number of code units written |
| 546 | with the length of the right slice (the output slice) to fix a panic |
| 547 | introduced in 0.8.11. |
| 548 | |
| 549 | ### 0.8.12 |
| 550 | |
| 551 | * Removed the `clippy::` prefix from clippy lint names. |
| 552 | |
| 553 | ### 0.8.11 |
| 554 | |
| 555 | * Changed minimum Rust requirement to 1.29.0 (for the ability to refer |
| 556 | to the interior of a `static` when defining another `static`). |
| 557 | * Explicitly aligned the lookup tables for single-byte encodings and |
| 558 | UTF-8 to cache lines in the hope of freeing up one cache line for |
| 559 | other data. (Perhaps the tables were already aligned and this is |
| 560 | placebo.) |
| 561 | * Added 32 bits of encode-oriented data for each single-byte encoding. |
| 562 | The change was performance-neutral for non-Latin1-ish Latin legacy |
| 563 | encodings, improved Latin1-ish and Arabic legacy encode speed |
| 564 | somewhat (new speed is 2.4x the old speed for German, 2.3x for |
| 565 | Arabic, 1.7x for Portuguese and 1.4x for French) and improved |
| 566 | non-Latin1, non-Arabic legacy single-byte encode a lot (7.2x for |
| 567 | Thai, 6x for Greek, 5x for Russian, 4x for Hebrew). |
| 568 | * Added compile-time options for fast CJK legacy encode options (at |
| 569 | the cost of binary size (up to 176 KB) and run-time memory usage). |
| 570 | These options still retain the overall code structure instead of |
| 571 | rewriting the CJK encoders totally, so the speed isn't as good as |
| 572 | what could be achieved by using even more memory / making the |
| 573 | binary even langer. |
| 574 | * Made UTF-8 decode and validation faster. |
| 575 | * Added method `is_single_byte()` on `Encoding`. |
| 576 | * Added `mem::decode_latin1()` and `mem::encode_latin1_lossy()`. |
| 577 | |
| 578 | ### 0.8.10 |
| 579 | |
| 580 | * Disabled a unit test that tests a panic condition when the assertion |
| 581 | being tested is disabled. |
| 582 | |
| 583 | ### 0.8.9 |
| 584 | |
| 585 | * Made `--features simd-accel` work with stable-channel compiler to |
| 586 | simplify the Firefox build system. |
| 587 | |
| 588 | ### 0.8.8 |
| 589 | |
| 590 | * Made the `is_foo_bidi()` not treat U+FEFF (ZERO WIDTH NO-BREAK SPACE |
| 591 | aka. BYTE ORDER MARK) as right-to-left. |
| 592 | * Made the `is_foo_bidi()` functions report `true` if the input contains |
| 593 | Hebrew presentations forms (which are right-to-left but not in a |
| 594 | right-to-left-roadmapped block). |
| 595 | |
| 596 | ### 0.8.7 |
| 597 | |
| 598 | * Fixed a panic in the UTF-16LE/UTF-16BE decoder when decoding to UTF-8. |
| 599 | |
| 600 | ### 0.8.6 |
| 601 | |
| 602 | * Temporarily removed the debug assertion added in version 0.8.5 from |
| 603 | `convert_utf16_to_latin1_lossy`. |
| 604 | |
| 605 | ### 0.8.5 |
| 606 | |
| 607 | * If debug assertions are enabled but fuzzing isn't enabled, lossy conversions |
| 608 | to Latin1 in the `mem` module assert that the input is in the range |
| 609 | U+0000...U+00FF (inclusive). |
| 610 | * In the `mem` module provide conversions from Latin1 and UTF-16 to UTF-8 |
| 611 | that can deal with insufficient output space. The idea is to use them |
| 612 | first with an allocation rounded up to jemalloc bucket size and do the |
| 613 | worst-case allocation only if the jemalloc rounding up was insufficient |
| 614 | as the first guess. |
| 615 | |
| 616 | ### 0.8.4 |
| 617 | |
| 618 | * Fix SSE2-specific, `simd-accel`-specific memory corruption introduced in |
| 619 | version 0.8.1 in conversions between UTF-16 and Latin1 in the `mem` module. |
| 620 | |
| 621 | ### 0.8.3 |
| 622 | |
| 623 | * Removed an `#[inline(never)]` annotation that was not meant for release. |
| 624 | |
| 625 | ### 0.8.2 |
| 626 | |
| 627 | * Made non-ASCII UTF-16 to UTF-8 encode faster by manually omitting bound |
| 628 | checks and manually adding branch prediction annotations. |
| 629 | |
| 630 | ### 0.8.1 |
| 631 | |
| 632 | * Tweaked loop unrolling and memory alignment for SSE2 conversions between |
| 633 | UTF-16 and Latin1 in the `mem` module to increase the performance when |
| 634 | converting long buffers. |
| 635 | |
| 636 | ### 0.8.0 |
| 637 | |
| 638 | * Changed the minimum supported version of Rust to 1.21.0 (semver breaking |
| 639 | change). |
| 640 | * Flipped around the defaults vs. optional features for controlling the size |
| 641 | vs. speed trade-off for Kanji and Hanzi legacy encode (semver breaking |
| 642 | change). |
| 643 | * Added NEON support on ARMv7. |
| 644 | * SIMD-accelerated x-user-defined to UTF-16 decode. |
| 645 | * Made UTF-16LE and UTF-16BE decode a lot faster (including SIMD |
| 646 | acceleration). |
| 647 | |
| 648 | ### 0.7.2 |
| 649 | |
| 650 | * Add the `mem` module. |
| 651 | * Refactor SIMD code which can affect performance outside the `mem` |
| 652 | module. |
| 653 | |
| 654 | ### 0.7.1 |
| 655 | |
| 656 | * When encoding from invalid UTF-16, correctly handle U+DC00 followed by |
| 657 | another low surrogate. |
| 658 | |
| 659 | ### 0.7.0 |
| 660 | |
| 661 | * [Make `replacement` a label of the replacement |
| 662 | encoding.](https://github.com/whatwg/encoding/issues/70) (Spec change.) |
| 663 | * Remove `Encoding::for_name()`. (`Encoding::for_label(foo).unwrap()` is |
| 664 | now close enough after the above label change.) |
| 665 | * Remove the `parallel-utf8` cargo feature. |
| 666 | * Add optional Serde support for `&'static Encoding`. |
| 667 | * Performance tweaks for ASCII handling. |
| 668 | * Performance tweaks for UTF-8 validation. |
| 669 | * SIMD support on aarch64. |
| 670 | |
| 671 | ### 0.6.11 |
| 672 | |
| 673 | * Make `Encoder::has_pending_state()` public. |
| 674 | * Update the `simd` crate dependency to 0.2.0. |
| 675 | |
| 676 | ### 0.6.10 |
| 677 | |
| 678 | * Reserve enough space for NCRs when encoding to ISO-2022-JP. |
| 679 | * Correct max length calculations for multibyte decoders. |
| 680 | * Correct max length calculations before BOM sniffing has been |
| 681 | performed. |
| 682 | * Correctly calculate max length when encoding from UTF-16 to GBK. |
| 683 | |
| 684 | ### 0.6.9 |
| 685 | |
| 686 | * [Don't prepend anything when gb18030 range decode |
| 687 | fails](https://github.com/whatwg/encoding/issues/110). (Spec change.) |
| 688 | |
| 689 | ### 0.6.8 |
| 690 | |
| 691 | * Correcly handle the case where the first buffer contains potentially |
| 692 | partial BOM and the next buffer is the last buffer. |
| 693 | * Decode byte `7F` correctly in ISO-2022-JP. |
| 694 | * Make UTF-16 to UTF-8 encode write closer to the end of the buffer. |
| 695 | * Implement `Hash` for `Encoding`. |
| 696 | |
| 697 | ### 0.6.7 |
| 698 | |
| 699 | * [Map half-width katakana to full-width katana in ISO-2022-JP |
| 700 | encoder](https://github.com/whatwg/encoding/issues/105). (Spec change.) |
| 701 | * Give `InputEmpty` correct precedence over `OutputFull` when encoding |
| 702 | with replacement and the output buffer passed in is too short or the |
| 703 | remaining space in the output buffer is too small after a replacement. |
| 704 | |
| 705 | ### 0.6.6 |
| 706 | |
| 707 | * Correct max length calculation when a partial BOM prefix is part of |
| 708 | the decoder's state. |
| 709 | |
| 710 | ### 0.6.5 |
| 711 | |
| 712 | * Correct max length calculation in various encoders. |
| 713 | * Correct max length calculation in the UTF-16 decoder. |
| 714 | * Derive `PartialEq` and `Eq` for the `CoderResult`, `DecoderResult` |
| 715 | and `EncoderResult` types. |
| 716 | |
| 717 | ### 0.6.4 |
| 718 | |
| 719 | * Avoid panic when encoding with replacement and the destination buffer is |
| 720 | too short to hold one numeric character reference. |
| 721 | |
| 722 | ### 0.6.3 |
| 723 | |
| 724 | * Add support for 32-bit big-endian hosts. (For real this time.) |
| 725 | |
| 726 | ### 0.6.2 |
| 727 | |
| 728 | * Fix a panic from subslicing with bad indices in |
| 729 | `Encoder::encode_from_utf16`. (Due to an oversight, it lacked the fix that |
| 730 | `Encoder::encode_from_utf8` already had.) |
| 731 | * Micro-optimize error status accumulation in non-streaming case. |
| 732 | |
| 733 | ### 0.6.1 |
| 734 | |
| 735 | * Avoid panic near integer overflow in a case that's unlikely to actually |
| 736 | happen. |
| 737 | * Address Clippy lints. |
| 738 | |
| 739 | ### 0.6.0 |
| 740 | |
| 741 | * Make the methods for computing worst-case buffer size requirements check |
| 742 | for integer overflow. |
| 743 | * Upgrade rayon to 0.7.0. |
| 744 | |
| 745 | ### 0.5.1 |
| 746 | |
| 747 | * Reorder methods for better documentation readability. |
| 748 | * Add support for big-endian hosts. (Only 64-bit case actually tested.) |
| 749 | * Optimize the ALU (non-SIMD) case for 32-bit ARM instead of x86_64. |
| 750 | |
| 751 | ### 0.5.0 |
| 752 | |
| 753 | * Avoid allocating an excessively long buffers in non-streaming decode. |
| 754 | * Fix the behavior of ISO-2022-JP and replacement decoders near the end of the |
| 755 | output buffer. |
| 756 | * Annotate the result structs with `#[must_use]`. |
| 757 | |
| 758 | ### 0.4.0 |
| 759 | |
| 760 | * Split FFI into a separate crate. |
| 761 | * Performance tweaks. |
| 762 | * CJK binary size and encoding performance changes. |
| 763 | * Parallelize UTF-8 validation in the case of long buffers (with optional |
| 764 | feature `parallel-utf8`). |
| 765 | * Borrow even with ISO-2022-JP when possible. |
| 766 | |
| 767 | ### 0.3.2 |
| 768 | |
| 769 | * Fix moving pointers to alignment in ALU-based ASCII acceleration. |
| 770 | * Fix errors in documentation and improve documentation. |
| 771 | |
| 772 | ### 0.3.1 |
| 773 | |
| 774 | * Fix UTF-8 to UTF-16 decode for byte sequences beginning with 0xEE. |
| 775 | * Make UTF-8 to UTF-8 decode SSE2-accelerated when feature `simd-accel` is used. |
| 776 | * When decoding and encoding ASCII-only input from or to an ASCII-compatible |
| 777 | encoding using the non-streaming API, return a borrow of the input. |
| 778 | * Make encode from UTF-16 to UTF-8 faster. |
| 779 | |
| 780 | ### 0.3 |
| 781 | |
| 782 | * Change the references to the instances of `Encoding` from `const` to `static` |
| 783 | to make the referents unique across crates that use the refernces. |
| 784 | * Introduce non-reference-typed `FOO_INIT` instances of `Encoding` to allow |
| 785 | foreign crates to initialize `static` arrays with references to `Encoding` |
| 786 | instances even under Rust's constraints that prohibit the initialization of |
| 787 | `&'static Encoding`-typed array items with `&'static Encoding`-typed |
| 788 | `statics`. |
| 789 | * Document that the above two points will be reverted if Rust changes `const` |
| 790 | to work so that cross-crate usage keeps the referents unique. |
| 791 | * Return `Cow`s from Rust-only non-streaming methods for encode and decode. |
| 792 | * `Encoding::for_bom()` returns the length of the BOM. |
| 793 | * ASCII-accelerated conversions for encodings other than UTF-16LE, UTF-16BE, |
| 794 | ISO-2022-JP and x-user-defined. |
| 795 | * Add SSE2 acceleration behind the `simd-accel` feature flag. (Requires |
| 796 | nightly Rust.) |
| 797 | * Fix panic with long bogus labels. |
| 798 | * Map [0xCA to U+05BA in windows-1255](https://github.com/whatwg/encoding/issues/73). |
| 799 | (Spec change.) |
| 800 | * Correct the [end of the Shift_JIS EUDC range](https://github.com/whatwg/encoding/issues/53). |
| 801 | (Spec change.) |
| 802 | |
| 803 | ### 0.2.4 |
| 804 | |
| 805 | * Polish FFI documentation. |
| 806 | |
| 807 | ### 0.2.3 |
| 808 | |
| 809 | * Fix UTF-16 to UTF-8 encode. |
| 810 | |
| 811 | ### 0.2.2 |
| 812 | |
| 813 | * Add `Encoder.encode_from_utf8_to_vec_without_replacement()`. |
| 814 | |
| 815 | ### 0.2.1 |
| 816 | |
| 817 | * Add `Encoding.is_ascii_compatible()`. |
| 818 | |
| 819 | * Add `Encoding::for_bom()`. |
| 820 | |
| 821 | * Make `==` for `Encoding` use name comparison instead of pointer comparison, |
| 822 | because uses of the encoding constants in different crates result in |
| 823 | different addresses and the constant cannot be turned into statics without |
| 824 | breaking other things. |
| 825 | |
| 826 | ### 0.2.0 |
| 827 | |
| 828 | The initial release. |