csv_lib/encoders/
latin1.rs1
2pub(crate) fn encode_latin1_scalar(input: &str) -> Vec<u8> {
3 input.chars().map(|c| {
4 if c as u32 <= 0xFF {
5 c as u8
6 } else {
7 b'?'
8 }
9 }).collect()
10}
11
12pub fn encode_latin1(input: &str) -> Vec<u8> {
13 encode_latin1_scalar(input)
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[test]
21 fn test_encode_latin1() {
22 let input = "Héllo";
23 let encoded = encode_latin1(input);
24 assert_eq!(encoded, vec![b'H', 0xE9, b'l', b'l', b'o']);
25 }
26}