#charset #local #utf-8 #8-bit #character-encoding #unicode-characters #ansi-codepage #oem-codepage

local-encoding

Rust library for encoding/decoding string with local charset. It usefull for work with ANSI strings on Windows.

2 unstable releases

Uses old Rust 2015

0.2.0 Aug 9, 2016
0.1.0 Jul 12, 2016

#35 in #charset

Download history 285/week @ 2025-10-03 418/week @ 2025-10-10 510/week @ 2025-10-17 551/week @ 2025-10-24 440/week @ 2025-10-31 772/week @ 2025-11-07 596/week @ 2025-11-14 952/week @ 2025-11-21 497/week @ 2025-11-28 571/week @ 2025-12-05 344/week @ 2025-12-12 386/week @ 2025-12-19 386/week @ 2025-12-26 364/week @ 2026-01-02 161/week @ 2026-01-09 384/week @ 2026-01-16

1,359 downloads per month
Used in 16 crates (14 directly)

MIT license

18KB
312 lines

local-encoding

Join the chat at https://gitter.im/bozaro/local-encoding-rs Build Status Crates.io

This repository contains rust library for encoding/decoding string with local charset. It usefull for work with ANSI strings on Windows.

Unfortunately Windows widly use 8-bit character encoding instead UTF-8. This causes a lot of pain.

For example, in Russian version:

  • CP-1251 (ANSI codepage) used for 8-bit files;
  • CP-866 (OEM codepage) used for console output.

To convert between 8-bit and Unicode used Windows have function: MultiByteToWideChar and WideCharToMultiByte.

This library provide simple function to convert between 8-bit and Unicode characters on Windows.

UTF-8 used as 8-bit codepage for non-Windows system.

Rustdoc: https://bozaro.github.io/local-encoding-rs/local_encoding/

Usage

Put this in your Cargo.toml:

[dependencies]
local-encoding = "*"

For example:

extern crate local_encoding;

use local_encoding::{Encoding, Encoder};

fn main()
{
	println!("Unicode string: {}", Encoding::ANSI.to_string(b"ANSI string").unwrap());
	println!("Unicode string: {}", Encoding::OEM.to_string(b"OEM string").unwrap());
}

Dependencies

~135KB