[][src]Function locale_name_code_page::get_codepage

pub fn get_codepage<'a, S: Into<Cow<'a, str>>>(
    encoding: S
) -> Option<&'static CodePage>

Suggests ANSI/OEM code pages used in Windows from the given locale name.

Locale names must be such as the following:

  1. It must consist of components that follows the regex [a-zA-Z]+.
  2. Its components must be joined by - or _. (e.g. en-US,en_us) Single components (e.g. en) are also allowed.
  3. Joined locales (e.g. en-US) may be joined by ,. (e.g. en-US,ja_JP) The first valid locale will be used.

Examples

 use locale_name_code_page::get_codepage;

if let Some(locale_en_us) = get_codepage("en-US") {
  assert_eq!(locale_en_us.ansi, 1252);
  assert_eq!(locale_en_us.oem, 437);
} else {
   panic!("en-US must be supported.");
}

assert_eq!(get_codepage("ja"), get_codepage("ja_JP"));
assert_eq!(get_codepage("en-gb").unwrap().oem, 850);
assert_eq!(get_codepage("invalid_locale"), None);
assert_eq!(get_codepage("invalid_locale,en"), get_codepage("en_us"));
assert_eq!(get_codepage("ja,en"), get_codepage("ja"));
assert_eq!(get_codepage("JA_JP,en-us"), get_codepage("ja"));