Remove unused dmm_tools::utils

This commit is contained in:
Tad Hardesty 2019-11-11 19:53:24 -08:00
parent a9c366d759
commit 8172d78535
2 changed files with 0 additions and 87 deletions

View file

@ -11,7 +11,6 @@ extern crate inflate;
extern crate linked_hash_map;
extern crate rand;
#[macro_use] mod utils;
pub mod dmm;
pub mod icon_cache;
pub mod minimap;

View file

@ -1,86 +0,0 @@
// ----------------------------------------------------------------------------
// Copy-paste of std::io::Chars for stability
use std::io::{self, Read, ErrorKind};
#[allow(dead_code)]
pub struct Chars<R> {
inner: R,
}
impl<R> Chars<R> {
#[allow(dead_code)]
pub fn new(inner: R) -> Chars<R> {
Chars { inner }
}
}
impl<R: Read> Iterator for Chars<R> {
type Item = io::Result<char>;
fn next(&mut self) -> Option<io::Result<char>> {
let first_byte = match read_one_byte(&mut self.inner) {
None => return None,
Some(Ok(b)) => b,
Some(Err(e)) => return Some(Err(e)),
};
let width = utf8_char_width(first_byte);
if width == 1 {
return Some(Ok(first_byte as char));
}
if width == 0 {
return Some(Err(ErrorKind::InvalidData.into()));
}
let mut buf = [first_byte, 0, 0, 0];
{
let mut start = 1;
while start < width {
match self.inner.read(&mut buf[start..width]) {
Ok(0) => return Some(Err(ErrorKind::InvalidData.into())),
Ok(n) => start += n,
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) => return Some(Err(e)),
}
}
}
Some(match ::std::str::from_utf8(&buf[..width]).ok() {
Some(s) => Ok(s.chars().next().unwrap()),
None => Err(ErrorKind::InvalidData.into()),
})
}
}
fn read_one_byte(reader: &mut dyn Read) -> Option<io::Result<u8>> {
let mut buf = [0];
loop {
return match reader.read(&mut buf) {
Ok(0) => None,
Ok(..) => Some(Ok(buf[0])),
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) => Some(Err(e)),
};
}
}
static UTF8_CHAR_WIDTH: [u8; 256] = [
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9F
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBF
0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDF
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEF
4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0, // 0xFF
];
#[inline]
fn utf8_char_width(b: u8) -> usize {
return UTF8_CHAR_WIDTH[b as usize] as usize;
}