mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
echo: fix handling of \0
This commit is contained in:
parent
76cf0e47ed
commit
df6f1ba19c
1 changed files with 10 additions and 8 deletions
18
echo/echo.rs
18
echo/echo.rs
|
@ -61,19 +61,22 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) {
|
||||||
|
|
||||||
let mut bytes = vec!();
|
let mut bytes = vec!();
|
||||||
for offset in range(0, max_digits) {
|
for offset in range(0, max_digits) {
|
||||||
|
if string.len() <= index + offset as uint {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let c = string[index + offset as uint];
|
let c = string[index + offset as uint];
|
||||||
if is_legal_digit(c) {
|
if is_legal_digit(c) {
|
||||||
bytes.push(c as u8);
|
bytes.push(c as u8);
|
||||||
} else {
|
} else {
|
||||||
if bytes.len() > 0 {
|
break;
|
||||||
return (to_char(&bytes, base), offset);
|
|
||||||
} else {
|
|
||||||
return (' ', offset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(to_char(&bytes, base), max_digits)
|
if bytes.len() == 0 {
|
||||||
|
(' ', 0)
|
||||||
|
} else {
|
||||||
|
(to_char(&bytes, base), bytes.len() as int)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
|
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
|
||||||
|
@ -181,8 +184,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
'0' => {
|
'0' => {
|
||||||
let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 8u);
|
let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 8u);
|
||||||
if num_char_used == 0 {
|
if num_char_used == 0 {
|
||||||
print_char('\\');
|
print_char('\0');
|
||||||
print_char('0');
|
|
||||||
} else {
|
} else {
|
||||||
print_char(c);
|
print_char(c);
|
||||||
for _ in range(0, num_char_used) {
|
for _ in range(0, num_char_used) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue