csv_lib/encoders/
windows1252.rs1
2pub(crate) fn encode_windows1252_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_windows1252(input: &str) -> Vec<u8> {
13 encode_windows1252_scalar(input)
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[test]
21 fn test_encode_windows1252() {
22 let input = "Hello€";
23 let encoded = encode_windows1252(input);
24 assert_eq!(encoded[0], b'H');
25 }
26}