mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
uniq: fix skip & check characters logic
This commit is contained in:
parent
676e3718c3
commit
fc5b798ff1
1 changed files with 3 additions and 11 deletions
|
@ -16,7 +16,6 @@ extern crate getopts;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use getopts::{Matches, Options};
|
use getopts::{Matches, Options};
|
||||||
use std::cmp::min;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, BufWriter, Read, stdin, stdout, Write};
|
use std::io::{BufRead, BufReader, BufWriter, Read, stdin, stdout, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -84,16 +83,9 @@ impl Uniq {
|
||||||
fn cmp_key(&self, line: &str) -> String {
|
fn cmp_key(&self, line: &str) -> String {
|
||||||
let len = line.len();
|
let len = line.len();
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
let slice_start = match self.slice_start {
|
line.chars()
|
||||||
Some(i) => min(i, len - 1),
|
.skip(self.slice_start.unwrap_or(0))
|
||||||
None => 0
|
.take(self.slice_stop.unwrap_or(len))
|
||||||
};
|
|
||||||
let slice_stop = match self.slice_stop {
|
|
||||||
Some(i) => min(slice_start + i, len),
|
|
||||||
None => len
|
|
||||||
};
|
|
||||||
|
|
||||||
line[slice_start..slice_stop].chars()
|
|
||||||
.map(|c| match c {
|
.map(|c| match c {
|
||||||
'a' ... 'z' if self.ignore_case => ((c as u8) - 32) as char,
|
'a' ... 'z' if self.ignore_case => ((c as u8) - 32) as char,
|
||||||
_ => c,
|
_ => c,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue