| 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)] |
| 16 |
pub mod lossy; |
| 17 |
|
| 18 |
// https://tools.ietf.org/html/rfc3629 |
| 19 |
#[rustfmt::skip] |
| 20 |
static UTF8_CHAR_WIDTH: [u8; 256] = [ |
| 21 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 22 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F |
| 23 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 24 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3F |
| 25 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 26 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5F |
| 27 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 28 |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7F |
| 29 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 30 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9F |
| 31 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 32 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBF |
| 33 |
0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2, |
| 34 |
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDF |
| 35 |
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEF |
| 36 |
4,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] |
| 41 |
pub fn utf8_char_width(b: u8) -> usize { |
| 42 |
UTF8_CHAR_WIDTH[b as usize] as usize |
| 43 |
} |