bumpalo/collections/str/
mod.rs

1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! String manipulation
12//!
13//! For more details, see std::str
14
15#[allow(missing_docs)]
16pub mod lossy;
17
18// https://tools.ietf.org/html/rfc3629
19#[rustfmt::skip]
20static UTF8_CHAR_WIDTH: [u8; 256] = [
211,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
221,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F
231,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
241,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3F
251,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
261,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5F
271,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
281,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7F
290,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
300,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9F
310,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
320,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBF
330,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
342,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDF
353,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEF
364,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0, // 0xFF
37];
38
39/// Given a first byte, determines how many bytes are in this UTF-8 character.
40#[inline]
41pub fn utf8_char_width(b: u8) -> usize {
42    UTF8_CHAR_WIDTH[b as usize] as usize
43}