mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 12:24:09 +00:00
Merge pull request #4983 from TheDcoder/parse-hex
od: fix parsing of hex input ending with `E`
This commit is contained in:
commit
8debc96eeb
|
@ -43,7 +43,7 @@ pub fn parse_number_of_bytes(s: &str) -> Result<u64, ParseSizeError> {
|
|||
len -= 1;
|
||||
}
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
Some('E') => {
|
||||
Some('E') if radix != 16 => {
|
||||
multiply = 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
|
||||
len -= 1;
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ fn test_parse_number_of_bytes() {
|
|||
|
||||
// hex input
|
||||
assert_eq!(15, parse_number_of_bytes("0xf").unwrap());
|
||||
assert_eq!(14, parse_number_of_bytes("0XE").unwrap());
|
||||
assert_eq!(15, parse_number_of_bytes("0XF").unwrap());
|
||||
assert_eq!(27, parse_number_of_bytes("0x1b").unwrap());
|
||||
assert_eq!(16 * 1024, parse_number_of_bytes("0x10k").unwrap());
|
||||
|
|
|
@ -627,6 +627,35 @@ fn test_skip_bytes() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_bytes_hex() {
|
||||
let input = "abcdefghijklmnopq"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-c")
|
||||
.arg("--skip-bytes=0xB")
|
||||
.run_piped_stdin(input.as_bytes())
|
||||
.no_stderr()
|
||||
.success()
|
||||
.stdout_is(unindent(
|
||||
"
|
||||
0000013 l m n o p q
|
||||
0000021
|
||||
",
|
||||
));
|
||||
new_ucmd!()
|
||||
.arg("-c")
|
||||
.arg("--skip-bytes=0xE")
|
||||
.run_piped_stdin(input.as_bytes())
|
||||
.no_stderr()
|
||||
.success()
|
||||
.stdout_is(unindent(
|
||||
"
|
||||
0000016 o p q
|
||||
0000021
|
||||
",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_bytes_error() {
|
||||
let input = "12345";
|
||||
|
|
Loading…
Reference in a new issue