Skip to content

Commit b65870b

Browse files
stty: more small edits after review
1 parent 2c3cff0 commit b65870b

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/uu/stty/src/stty.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,9 @@ fn apply_char_mapping(
501501
control_char_index: SpecialCharacterIndices,
502502
new_val: &str,
503503
) -> Result<(), ControlCharMappingError> {
504-
match string_to_control_char(new_val) {
505-
Ok(val) => {
506-
termios.control_chars[control_char_index as usize] = val;
507-
Ok(())
508-
}
509-
Err(e) => Err(e),
510-
}
504+
string_to_control_char(new_val).map(|val| {
505+
termios.control_chars[control_char_index as usize] = val;
506+
})
511507
}
512508

513509
// GNU stty defines some valid values for the control character mappings
@@ -518,21 +514,20 @@ fn apply_char_mapping(
518514
// c. decimal, no prefix
519515
// 3. Disabling the control character: '^-' or 'undef'
520516
//
521-
// This function returns the ascii value of valid control chars, or None if the input is invalid
517+
// This function returns the ascii value of valid control chars, or ControlCharMappingError if invalid
522518
fn string_to_control_char(s: &str) -> Result<u8, ControlCharMappingError> {
523519
if s == "undef" || s == "^-" {
524520
return Ok(0);
525521
}
526522

527523
// try to parse integer (hex, octal, or decimal)
528-
let mut ascii_num: Option<u32> = None;
529-
if let Some(hex) = s.strip_prefix("0x") {
530-
ascii_num = u32::from_str_radix(hex, 16).ok();
524+
let ascii_num = if let Some(hex) = s.strip_prefix("0x") {
525+
u32::from_str_radix(hex, 16).ok()
531526
} else if let Some(octal) = s.strip_prefix("0") {
532-
ascii_num = u32::from_str_radix(octal, 8).ok();
533-
} else if let Ok(decimal) = s.parse::<u32>() {
534-
ascii_num = Some(decimal);
535-
}
527+
u32::from_str_radix(octal, 8).ok()
528+
} else {
529+
s.parse::<u32>().ok()
530+
};
536531

537532
if let Some(val) = ascii_num {
538533
if val > 255 {

0 commit comments

Comments
 (0)