Skip to content

Commit

Permalink
refactor(parser): Switch to bstr for line splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 14, 2019
1 parent 9a3aef7 commit 4ce7303
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 58 deletions.
80 changes: 24 additions & 56 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ ignore = "0.4"
phf = { version = "0.7", features = ["unicase"] }
regex = "1.0"
lazy_static = "1.2.0"
grep-searcher = "0.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
itertools = "0.8"
unicase = "1.1"
bstr = "0.2"

[dev-dependencies]
assert_fs = "0.10"
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub use crate::dict::*;
use std::fs::File;
use std::io::Read;

use bstr::ByteSlice;

pub fn process_file(
path: &std::path::Path,
dictionary: &Dictionary,
Expand All @@ -20,7 +22,8 @@ pub fn process_file(
) -> Result<(), failure::Error> {
let mut buffer = Vec::new();
File::open(path)?.read_to_end(&mut buffer)?;
for (line_idx, line) in grep_searcher::LineIter::new(b'\n', &buffer).enumerate() {

for (line_idx, line) in buffer.lines().enumerate() {
let line_num = line_idx + 1;
for ident in tokens::Identifier::parse(line) {
if !ignore_hex && is_hex(ident.token()) {
Expand Down

0 comments on commit 4ce7303

Please sign in to comment.