char-iter 0.1.0

A performant iterator over a linear range of characters (`char`s), correctly handling the surrogate range.

Crate char_iter [] [src]

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}']);

Structs

Iter

An iterator over a linear range of characters.

Functions

new

Create a new iterator over the characters (specifically Unicode Scalar Values) from start to end, inclusive.