Get WideCharToMultiByte flags for encoding. Matches encode_code_page_flags() in CPython.
(code_page: u32, errors: &str)
| 769 | /// Get WideCharToMultiByte flags for encoding. |
| 770 | /// Matches encode_code_page_flags() in CPython. |
| 771 | fn encode_code_page_flags(code_page: u32, errors: &str) -> u32 { |
| 772 | use windows_sys::Win32::Globalization::{WC_ERR_INVALID_CHARS, WC_NO_BEST_FIT_CHARS}; |
| 773 | if code_page == 65001 { |
| 774 | // CP_UTF8 |
| 775 | WC_ERR_INVALID_CHARS |
| 776 | } else if code_page == 65000 { |
| 777 | // CP_UTF7 only supports flags=0 |
| 778 | 0 |
| 779 | } else if errors == "replace" { |
| 780 | 0 |
| 781 | } else { |
| 782 | WC_NO_BEST_FIT_CHARS |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | /// Try to encode the entire wide string at once (fast/strict path). |
| 787 | /// Returns Ok(Some(bytes)) on success, Ok(None) if there are unencodable chars, |
no outgoing calls
no test coverage detected