#iterator #unicode #range #surrogate #characters #linear #correctly

char-iter

A performant iterator over a linear range of characters (chars), correctly handling the surrogate range

1 unstable release

Uses old Rust 2015

0.1.0 Apr 21, 2015

#5 in #correctly

Download history 10/week @ 2024-03-18 14/week @ 2024-03-25 40/week @ 2024-04-01 9/week @ 2024-04-08 7/week @ 2024-04-15 8/week @ 2024-04-22 7/week @ 2024-04-29 5/week @ 2024-05-06 16/week @ 2024-05-13 23/week @ 2024-05-20 22/week @ 2024-05-27 26/week @ 2024-06-03 23/week @ 2024-06-10 22/week @ 2024-06-17 23/week @ 2024-06-24

69 downloads per month

MIT/Apache

9KB
204 lines

char-iter

Build Status

This crates provides a performant iterator over a linear range of characters, correctly handling the surrogate range.

Documentation, crates.io.


lib.rs:

This crates provides a performant iterator over a linear range of characters.

The iterator is inclusive of its endpoint, and correctly handles the surrogate range (0xD800-0xDFFF). This induces only one extra branch (or conditional-move) compared to a direct x..y integer iterator that doesn't handle the surrogate range.

Source

Installation

Add this to your Cargo.toml:

[dependencies]
char-iter = "0.1"

Examples

let v: Vec<char> = char_iter::new('a', 'f').collect();
assert_eq!(v, &['a', 'b', 'c', 'd', 'e', 'f']);

Reverse iteration is supported:

// (codepoints 224 to 230)
let v: Vec<char> = char_iter::new('à', 'æ').rev().collect();
assert_eq!(v, &['æ', 'å', 'ä', 'ã', 'â', 'á', 'à']);

The surrogate range is skipped:

let v: Vec<char> = char_iter::new('\u{D7FF}', '\u{E000}').collect();
// 0xD800, ... 0xDFFF are missing
assert_eq!(v, &['\u{D7FF}', '\u{E000}']);

No runtime deps

Features