#iterator #range #unicode #characters #linear #surrogate #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

#6 in #surrogate

47 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