+use encoding_rs::{Encoding, UTF_8};
+
include!(concat!(env!("OUT_DIR"), "/encodings.rs"));
pub fn codepage_from_encoding(encoding: &str) -> Option<u32> {
}
use thiserror::Error as ThisError;
+
+use crate::locale_charset::locale_charset;
#[derive(ThisError, Debug)]
pub enum Error {
#[error("This system file does not indicate its own character encoding. For best results, specify an encoding explicitly. Use SYSFILE INFO with ENCODING=\"DETECT\" to analyze the possible encodings.")]
Ebcdic,
}
-/// Returns the character set used by the locale configured in the operating
-/// system. This should implement roughly the same behavior as the function
-/// with the same name in Gnulib. Until then, we'll just use a default.
-pub fn locale_charset() -> &'static str {
- "UTF-8"
+
+pub fn default_encoding() -> &'static Encoding {
+ lazy_static! {
+ static ref DEFAULT_ENCODING: &'static Encoding = {
+ Encoding::for_label(locale_charset()).unwrap_or(&UTF_8)
+ };
+ }
+ DEFAULT_ENCODING
}
pub fn get_encoding(encoding: Option<&str>, character_code: Option<i32>) -> Result<&str, Error> {