#utf-8 #iterator #unicode

utf8_iter

Iterator by char over potentially-invalid UTF-8 in &[u8]

5 stable releases

1.0.4 Dec 1, 2023
1.0.3 Sep 9, 2022
1.0.1 Jul 19, 2022
1.0.0 Apr 19, 2022

#354 in Text processing

Download history 18388/week @ 2024-03-14 17430/week @ 2024-03-21 14613/week @ 2024-03-28 16143/week @ 2024-04-04 20556/week @ 2024-04-11 21252/week @ 2024-04-18 15217/week @ 2024-04-25 18116/week @ 2024-05-02 15075/week @ 2024-05-09 16875/week @ 2024-05-16 20459/week @ 2024-05-23 18161/week @ 2024-05-30 265750/week @ 2024-06-06 568966/week @ 2024-06-13 241779/week @ 2024-06-20 144185/week @ 2024-06-27

1,223,756 downloads per month
Used in 162 crates (5 directly)

Apache-2.0 OR MIT

27KB
444 lines

utf8_iter

crates.io docs.rs

utf8_iter provides iteration by char over potentially-invalid UTF-8 &[u8] such that UTF-8 errors are handled according to the WHATWG Encoding Standard.

Iteration by Result<char,Utf8CharsError> is provided as an alternative that distinguishes UTF-8 errors from U+FFFD appearing in the input.

An implementation of char_indices() analogous to the same-name method on str is also provided.

Key parts of the code are copypaste from the UTF-8 to UTF-16 conversion code in encoding_rs, which was optimized for speed in the case of valid input. The implementation here uses the structure that was found to be fast in the encoding_rs context but the structure hasn't been benchmarked in this context.

This is a no_std crate.

Licensing

TL;DR: Apache-2.0 OR MIT

Please see the file named COPYRIGHT.

Documentation

Generated API documentation is available online.

Release Notes

1.0.4

  • Add iteration by Result<char,Utf8CharsError>.

1.0.3

  • Fix an error in documentation.

1.0.2

  • char_indices() implementation.

1.0.1

  • as_slice() method.
  • Implement DoubleEndedIterator

1.0.0

The initial release.

No runtime deps