From cb63a82646805f2d0d4bf41a0faaa97497814efa Mon Sep 17 00:00:00 2001 From: JIe Date: Thu, 21 Nov 2024 09:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/prehandle.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/prehandle.rs b/src/prehandle.rs index 70c3a88..6eb93a6 100644 --- a/src/prehandle.rs +++ b/src/prehandle.rs @@ -1,8 +1,9 @@ use std::{io::Read, path::PathBuf}; use std::fs::File; use std::io::{BufRead, BufReader, Cursor}; +use std::ptr::read; -pub fn handle(path: PathBuf,filter_str:String, start_index: u32, end_index: u32) -> Box{ +pub fn handle(path: PathBuf, filter_str:String, start_index: u32, end_index: u32) -> Box{ let reader = BufReader::new(File::open(path).unwrap()); let mut lines = reader.lines().collect::, _>>().unwrap(); lines = filter_by_string(lines, filter_str.as_str()); @@ -22,6 +23,9 @@ fn filter_by_string(reader: Vec, filter_str: &str) ->Vec{ } fn take(reader: &mut Vec, start_index: u32, end_index: u32) -> Vec { + if end_index < 0 && start_index < 0{ + panic!("start_index and end_index must be positive"); + } if end_index == 0 && start_index == 0{ return reader.to_owned(); } @@ -30,8 +34,10 @@ fn take(reader: &mut Vec, start_index: u32, end_index: u32) -> Vec