encoding_utils/
windows.rs

1pub use codepage::*;
2use encoding_rs::Encoding;
3use windows_sys::Win32::Globalization::GetACP;
4
5pub type CodePage = u32;
6
7/// Get Current ANSI Code Page via Windows API
8pub fn current_acp() -> CodePage {
9    unsafe { GetACP() }
10}
11
12pub fn current_acp_encoding() -> Option<&'static Encoding> {
13    let acp = current_acp();
14    to_encoding(acp as u16)
15}
16
17pub fn current_acp_encoding_no_replacement() -> Option<&'static Encoding> {
18    let acp = current_acp();
19    to_encoding_no_replacement(acp as u16)
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25
26    #[test]
27    fn test_get_current_acp() {
28        let acp = current_acp();
29        eprintln!("Current ANSI Code Page: {}", acp);
30        assert_ne!(acp, 0);
31    }
32
33    #[test]
34    fn test_get_current_acp_encoding() {
35        let encoding = current_acp_encoding();
36        eprintln!("Current ANSI Code Page Encoding: {:?}", encoding);
37        assert!(encoding.is_some());
38    }
39
40    #[test]
41    fn test_get_current_acp_encoding_no_replacement() {
42        let encoding = current_acp_encoding_no_replacement();
43        eprintln!(
44            "Current ANSI Code Page Encoding (no replacement): {:?}",
45            encoding
46        );
47        assert!(encoding.is_some());
48    }
49}