Skip to content

Commit

Permalink
update to 2021 edition, fix bug with opening blank (0 byte) files
Browse files Browse the repository at this point in the history
  • Loading branch information
geremachek committed Dec 24, 2021
1 parent 8512a68 commit 3ce19ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "merlin"
version = "2.2.2"
version = "2.2.3"
authors = ["geremachek <[email protected]>"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
19 changes: 15 additions & 4 deletions src/volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use std::{
use gapbuf::{GapBuffer, gap_buffer};
use crate::error::MerlinError;

// create a blank line GapBuffer

fn blank_line() -> GapBuffer<GapBuffer<char>> {
gap_buffer![GapBuffer::new()]
}

// create a GapBuffer of characters

fn gb_of_chars(s: &str) -> GapBuffer<char> {
Expand Down Expand Up @@ -46,8 +52,8 @@ impl Volume {

// fall back if there isn't any text supplied

if buff.len() == 0 {
buff = gap_buffer![GapBuffer::new()];
if buff.is_empty() {
buff = blank_line();
}

Volume {
Expand All @@ -62,7 +68,7 @@ impl Volume {
// create a buffer from a file

pub fn from_file(fpath: &str) -> Result<Volume, MerlinError> {
let mut buff = GapBuffer::new();
let mut buff = blank_line();
let mut w = true;

let path = PathBuf::from(fpath);
Expand All @@ -75,11 +81,16 @@ impl Volume {
for line in BufReader::new(file).lines() {
buff.push_back(gb_of_chars(&line.or(Err(MerlinError::ReadFailed))?));
}

// remove the blank line if we have successfully populated the buffer

if buff.len() > 1 {
buff.pop_front();
}
}
Err(_) => return Err(MerlinError::ReadFailed),
}
} else {
buff.push_back(GapBuffer::new());
w = false;
}

Expand Down

0 comments on commit 3ce19ae

Please sign in to comment.