Crates.io | locale_name_code_page |
lib.rs | locale_name_code_page |
version | 0.1.0 |
source | src |
created_at | 2020-09-13 15:55:38.356721 |
updated_at | 2020-09-13 15:55:38.356721 |
description | Rust library that helps us get code pages (then legacy encodings) used in Windows |
homepage | |
repository | https://github.com/tats-u/locale-name-code-page/ |
max_upload_size | |
id | 288230 |
size | 748,549 |
This is a library that converts strings representing locale names to code pages that are used in Windows.
e.g.
en-US
locale, Windows-1252 (code page id: 1252
) is used as the ANSI code page, and CP437 (code page id: 437
) is used as the OEM code page.ja-JP
locale, Shift_JIS (code page id: 932
) is used as both of the ANSI and OEM code pages.First, add locale_name_code_page = "<2"
to your Cargo.toml
.
[dependencies]
# *snip*
locale_name_code_page = "<2"
# *snip*
Then, convert strings representing locales to code pages like:
use locale_name_code_page::get_codepage;
use locale_name_code_page::cp_table_type::CodePage;
// IConverter has already been defined by you
fn get_converter_instance(codepage: &CodePage) -> Box<dyn IConverter> {
// do something
return Box::new(converter);
}
// *snip*
fn main() {
// *snip*
if let Some(codepage_ref) = get_codepage(locale_string) {
let converter = get_converter_instance(codepage_ref);
// *snip*
} else {
eprintln!("Error: {} doesn't represent a valid locale.", locale_string);
std::process::exit(1);
}
}
Obtained codepage (instance of locale_name_code_page::cp_table_type::CodePage
) can be used as follows:
use locale_name_code_page::get_codepage;
fn main() {
let en_cp = get_codepage("en-US").unwrap();
// prints "en-US locale: 1252 (ANSI) / 437 (OEM)"
println!("en-US locale: {} (ANSI) / {} (OEM)", en_cp.ansi, en_cp.oem);
}
Use the following libraries:
Combine with codepage and encoding_rs.
Use oem_cp.
Use locale_config.
You can use assets/nls_info.json
in your automatic code generation script.
MIT