-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from gorbit99/master
Support non-utf8 encoding
- Loading branch information
Showing
11 changed files
with
93 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
edition = "2018" | ||
struct_field_align_threshold = 40 | ||
max_width = 120 | ||
comment_width = 120 | ||
reorder_imports = true | ||
fn_single_line = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub(crate) mod core; | ||
pub mod lossy_reader; | ||
pub use crate::core::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::io::{self, BufRead, BufReader, Read}; | ||
|
||
pub struct LossyReader<R> { | ||
inner: BufReader<R>, | ||
} | ||
|
||
impl<R: Read> LossyReader<R> { | ||
pub fn new(inner: R) -> Self { | ||
Self { | ||
inner: BufReader::new(inner), | ||
} | ||
} | ||
} | ||
|
||
impl<R: Read> Read for LossyReader<R> { | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
self.inner.read(buf) | ||
} | ||
} | ||
|
||
impl<R: Read> BufRead for LossyReader<R> { | ||
fn fill_buf(&mut self) -> io::Result<&[u8]> { | ||
self.inner.fill_buf() | ||
} | ||
|
||
fn consume(&mut self, amt: usize) { | ||
self.inner.consume(amt) | ||
} | ||
|
||
fn read_line(&mut self, buf: &mut String) -> std::io::Result<usize> { | ||
let mut bytes = Vec::new(); | ||
let len = self.read_until(b'\n', &mut bytes)?; | ||
buf.push_str(&String::from_utf8_lossy(&bytes)); | ||
Ok(len) | ||
} | ||
} |