mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #3046 from hbina/hbina-tail-head-dont-use-is-numeric-to-check-digits
tail&head: dont use is_numeric to check for digits
This commit is contained in:
commit
252e30c839
5 changed files with 16 additions and 2 deletions
|
@ -20,7 +20,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
|
||||||
let mut has_num = false;
|
let mut has_num = false;
|
||||||
let mut last_char = 0 as char;
|
let mut last_char = 0 as char;
|
||||||
for (n, c) in &mut chars {
|
for (n, c) in &mut chars {
|
||||||
if c.is_numeric() {
|
if c.is_digit(10) {
|
||||||
has_num = true;
|
has_num = true;
|
||||||
num_end = n;
|
num_end = n;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
|
||||||
let mut has_num = false;
|
let mut has_num = false;
|
||||||
let mut last_char = 0 as char;
|
let mut last_char = 0 as char;
|
||||||
for (n, c) in &mut chars {
|
for (n, c) in &mut chars {
|
||||||
if c.is_numeric() {
|
if c.is_digit(10) {
|
||||||
has_num = true;
|
has_num = true;
|
||||||
num_end = n;
|
num_end = n;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -306,6 +306,10 @@ fn test_head_invalid_num() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "-³"])
|
||||||
|
.fails()
|
||||||
|
.stderr_is("head: invalid number of bytes: '³'");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -36,6 +36,12 @@ fn test_group_num() {
|
||||||
assert_eq!("", group_num(""));
|
assert_eq!("", group_num(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_group_num_panic_if_invalid_numeric_characters() {
|
||||||
|
group_num("³³³³³");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_generate_tokens {
|
mod test_generate_tokens {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -491,6 +491,10 @@ fn test_tail_invalid_num() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "-³"])
|
||||||
|
.fails()
|
||||||
|
.stderr_is("tail: invalid number of bytes: '³'");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue