MCPcopy Index your code
hub / github.com/RustPython/RustPython / encode_code_page_flags

Function encode_code_page_flags

crates/vm/src/stdlib/_codecs.rs:771–784  ·  view source on GitHub ↗

Get WideCharToMultiByte flags for encoding. Matches encode_code_page_flags() in CPython.

(code_page: u32, errors: &str)

Source from the content-addressed store, hash-verified

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,

Callers 2

encode_code_page_errorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected