GSTrans string conversion: Difference between revisions

m
use match
m (convert some chars to escaped chars for better printing)
m (use match)
Line 647:
{{trans|Julia}}
<syntaxhighlight lang="rust">fn gs_char_encode(i: u8) -> String {
let c = i as char;
let mut resultchars = Vec::<u8>::new();
ifmatch i <= 31 {
0..=31 => { resultchars.extend(['|' as u8, 64 + i]); }
} else if c 0x22 ==> { resultchars.extend(['|' as u8, '"' {as u8]) }
0x7c => { resultchars.extend(['|' as u8, '"|' as u8]); }
} else if c 127 ==> { resultchars.extend(['|' {as u8, '?' as u8]) }
128..=255 => { // |! then recurse after subtracting 128
resultchars.extend(['|' as u8, '|!' as u8]);
} else if i == 127 {
resultchars.extend(['|'gs_char_encode(i as- u8, '?' as u8]128).as_bytes());
} else if i >= 128 {}
_ => { resultchars.push(i); }
// |! then recurse after subtracting 128
resultchars.extend(['|' as u8, '!' as u8]);
resultchars.extend(gs_char_encode(i - 128).as_bytes());
} else {
resultchars.push(i);
}
return String::from_utf8_lossy(&resultchars).to_string();
4,103

edits