Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Option return for read_line #48

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/code_pair_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ impl<T: Read> TextCodePairIter<T> {
let code_line = if self.read_first_line {
self.offset += 1;
match read_line(&mut self.reader, true, encoding_rs::WINDOWS_1252) {
Some(Ok(v)) => v,
Some(Err(e)) => return Some(Err(e)),
None => return None,
Ok(v) => v,
Err(e) => return Some(Err(e)),
}
} else {
self.read_first_line = true;
Expand All @@ -106,9 +105,8 @@ impl<T: Read> TextCodePairIter<T> {
// Read value. If no line is available die horribly.
self.offset += 1;
let value_line = match read_line(&mut self.reader, false, self.string_encoding) {
Some(Ok(v)) => v,
Some(Err(e)) => return Some(Err(e)),
None => return Some(Err(DxfError::UnexpectedEndOfInput)),
Ok(v) => v,
Err(e) => return Some(Err(e)),
};

// construct the value pair
Expand Down
6 changes: 1 addition & 5 deletions src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ impl Drawing {
where
T: Read + ?Sized,
{
let first_line = match read_line(reader, true, encoding) {
Some(Ok(line)) => line,
Some(Err(e)) => return Err(e),
None => return Err(DxfError::UnexpectedEndOfInput),
};
let first_line = read_line(reader, true, encoding)?;
match &*first_line {
"AutoCAD DXB 1.0" => {
let mut reader = DxbReader::new(reader);
Expand Down
8 changes: 4 additions & 4 deletions src/helper_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub(crate) fn read_line<T>(
reader: &mut T,
allow_bom: bool,
encoding: &'static Encoding,
) -> Option<DxfResult<String>>
) -> DxfResult<String>
where
T: Read + ?Sized,
{
Expand All @@ -309,7 +309,7 @@ where
for (i, b) in reader_bytes.enumerate() {
let b = match b {
Ok(b) => b,
Err(e) => return Some(Err(DxfError::IoError(e))),
Err(e) => return Err(DxfError::IoError(e)),
};
match (i, b) {
(0, 0xEF) if allow_bom => {
Expand All @@ -327,14 +327,14 @@ where

let mut result = match encoding.decode(&bytes) {
(result, _, false) => String::from(&*result),
(_, _, true) => return Some(Err(DxfError::MalformedString)),
(_, _, true) => return Err(DxfError::MalformedString),
};

if result.ends_with('\r') {
result.pop();
}

Some(Ok(result))
Ok(result)
}

pub(crate) fn read_u8<T: Read + ?Sized>(reader: &mut T) -> Option<io::Result<u8>> {
Expand Down