mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
format: %c prints the first character of a string
This commit is contained in:
parent
7dc4afb5cc
commit
5dfeca9ff2
2 changed files with 9 additions and 8 deletions
|
@ -41,14 +41,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) => {
|
FormatArgument::Unparsed(s) => {
|
||||||
let mut chars = s.chars();
|
s.chars().next().unwrap_or('\0')
|
||||||
let Some(c) = chars.next() else {
|
|
||||||
return '\0';
|
|
||||||
};
|
|
||||||
let None = chars.next() else {
|
|
||||||
return '\0';
|
|
||||||
};
|
|
||||||
c
|
|
||||||
}
|
}
|
||||||
_ => '\0',
|
_ => '\0',
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,14 @@ fn sub_char() {
|
||||||
.stdout_only("the letter A");
|
.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]
|
#[test]
|
||||||
fn sub_num_int() {
|
fn sub_num_int() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue