#codepoint #utf8 #automaton #range


Convert ranges of Unicode codepoints to UTF-8 byte ranges

6 releases (2 stable)

1.0.1 Aug 25, 2018
1.0.0 Dec 30, 2016
0.1.3 Oct 17, 2015

#2 in Text processing

Download history 40405/week @ 2018-06-03 47805/week @ 2018-06-10 44124/week @ 2018-06-17 47750/week @ 2018-06-24 48998/week @ 2018-07-01 46594/week @ 2018-07-08 49471/week @ 2018-07-15 51033/week @ 2018-07-22 47821/week @ 2018-07-29 51268/week @ 2018-08-05 49599/week @ 2018-08-12 46646/week @ 2018-08-19 48836/week @ 2018-08-26

206,782 downloads per month
Used in 3,523 crates (5 directly)


333 lines


This crate converts contiguous ranges of Unicode scalar values to UTF-8 byte ranges. This is useful when constructing byte based automata from Unicode. Stated differently, this lets one embed UTF-8 decoding as part of one's automaton.

Linux build status

Dual-licensed under MIT or the UNLICENSE.




This shows how to convert a scalar value range (e.g., the basic multilingual plane) to a sequence of byte based character classes.

extern crate utf8_ranges;

use utf8_ranges::Utf8Sequences;

fn main() {
    for range in Utf8Sequences::new('\u{0}', '\u{FFFF}') {
        println!("{:?}", range);

The output:


These ranges can then be used to build an automaton. Namely:

  1. Every arbitrary sequence of bytes matches exactly one of the sequences of ranges or none of them.
  2. Every match sequence of bytes is guaranteed to be valid UTF-8. (Erroneous encodings of surrogate codepoints in UTF-8 cannot match any of the byte ranges above.)

No runtime deps