Skip to content

Commit

Permalink
format: %c prints the first character of a string
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Jan 4, 2024
1 parent be81602 commit 15ae059
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/uucore/src/lib/features/format/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ impl<'a, T: Iterator<Item = &'a FormatArgument>> ArgumentIter<'a> for T {
match next {
FormatArgument::Char(c) => *c,
FormatArgument::Unparsed(s) => {
let mut chars = s.chars();
let Some(c) = chars.next() else {
return '\0';
};
let None = chars.next() else {
return '\0';
};
c
s.chars().next().unwrap_or('\0')
}
_ => '\0',
}
Expand Down
8 changes: 8 additions & 0 deletions tests/by-util/test_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ fn sub_char() {
.stdout_only("the letter A");
}

#[test]
fn sub_char_from_string() {
new_ucmd!()
.args(&["%c%c%c", "five", "%", "oval"])
.succeeds()
.stdout_only("f%o");
}

#[test]
fn sub_num_int() {
new_ucmd!()
Expand Down

0 comments on commit 15ae059

Please sign in to comment.