1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

printf: %c prints the first byte of its argument

This commit is contained in:
Samuel Tardieu 2024-01-10 18:19:56 +01:00
parent 0071442cba
commit 7d32e49fb9
2 changed files with 6 additions and 1 deletions

View file

@ -45,7 +45,7 @@ impl<'a, T: Iterator<Item = &'a FormatArgument>> ArgumentIter<'a> for T {
}; };
match next { match next {
FormatArgument::Char(c) => *c, FormatArgument::Char(c) => *c,
FormatArgument::Unparsed(s) => s.chars().next().unwrap_or('\0'), FormatArgument::Unparsed(s) => s.bytes().next().map_or('\0', char::from),
_ => '\0', _ => '\0',
} }
} }

View file

@ -639,3 +639,8 @@ fn partial_char() {
"printf: warning: bc: character(s) following character constant have been ignored\n", "printf: warning: bc: character(s) following character constant have been ignored\n",
); );
} }
#[test]
fn char_as_byte() {
new_ucmd!().args(&["%c", "🙃"]).succeeds().stdout_only("ð");
}