From fc5b798ff183ca6c565a608b3c361c2c25e1361b Mon Sep 17 00:00:00 2001 From: "Chirag B. Jadwani" Date: Mon, 29 Feb 2016 11:10:38 +0530 Subject: [PATCH] uniq: fix skip & check characters logic --- src/uniq/uniq.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index f0e51e872..1ffd12a8a 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -16,7 +16,6 @@ extern crate getopts; extern crate uucore; use getopts::{Matches, Options}; -use std::cmp::min; use std::fs::File; use std::io::{BufRead, BufReader, BufWriter, Read, stdin, stdout, Write}; use std::path::Path; @@ -84,16 +83,9 @@ impl Uniq { fn cmp_key(&self, line: &str) -> String { let len = line.len(); if len > 0 { - let slice_start = match self.slice_start { - Some(i) => min(i, len - 1), - None => 0 - }; - let slice_stop = match self.slice_stop { - Some(i) => min(slice_start + i, len), - None => len - }; - - line[slice_start..slice_stop].chars() + line.chars() + .skip(self.slice_start.unwrap_or(0)) + .take(self.slice_stop.unwrap_or(len)) .map(|c| match c { 'a' ... 'z' if self.ignore_case => ((c as u8) - 32) as char, _ => c,