1 unstable release
Uses old Rust 2015
0.1.0 | Apr 21, 2015 |
---|
#5 in #correctly
69 downloads per month
9KB
204 lines
char-iter
This crates provides a performant iterator over a linear range of characters, correctly handling the surrogate range.
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.
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}']);