#utf-16 #utf-8 #unicode #decode #encode #encode-decode

bin+lib ende

A library for encoding/decoding unicode/utf-8/utf-16(ucs-2) code points

1 unstable release

0.1.0 Apr 14, 2024

#1378 in Text processing

GPL-3.0 license

49KB
378 lines

GitHub CI Linux GitHub CI Windows GitHub CI macOS Crates.io GitHub License Crates.io Downloads dependents Documentation

Encdec

A library for encoding/decoding unicode/utf-8/utf-16(ucs-2) code points.

Examples

Encoding/decoding unicode/UTF-8 code points

let v: Vec<u32> = vec![0x10348 /*...*/]; // Array of unicode code points
let utf8_vec: Vec<u8> = utf8::encode_in_utf8(&v);
utf8::print_utf8_b(&utf8_vec);
let unicode_vec: Vec<u32> = utf8::decode_from_utf8(&utf8_vec);
unicode::print_unicode_b(&v);
--------------- UTF-8 of "𐍈" ---------------
Hex: [f0, 90, 8d, 88]
Bin: ["11110000", "10010000", "10001101", "10001000"]
Dec: [240, 144, 141, 136]
--------------------------------------------

--------------- UNICODE of "𐍈" ---------------
Hex: [10348]
Bin: ["10000001101001000"]
Dec: [66376]
----------------------------------------------

Encoding/decoding unicode/UTF-16 code points

let v: Vec<u32> = vec![0x10001 /*...*/]; // Array of unicode code points
let utf16_vec: Vec<u16> = utf16::encode_in_utf16(&v);
utf16::print_utf16_b(&utf16_vec);
let unicode_vec: Vec<u32> = utf16::decode_from_utf16(&utf16_vec);
unicode::print_unicode_b(&v);
--------------- UTF-16 of "𐀁" ---------------
Hex: [d800, dc01]
Bin: ["1101100000000000", "1101110000000001"]
Dec: [55296, 56321]
---------------------------------------------

--------------- UNICODE of "𐀁" ---------------
Hex: [10001]
Bin: ["10000000000000001"]
Dec: [65537]
----------------------------------------------

Building

You can use just, make or cargo, as build tools. If you want to use cargo, please make sure to read the Justfile or the Makefile to understand the flags used for each command. Here are the available commands:

just COMMAND
make COMMAND

COMMAND:
  all    # fmt, clippy, test, build
  build  # Build the project
  run    # Run the project
  fmt    # Format the code
  clippy # Run clippy
  test   # Run the tests
  clean  # Clean the project
  help   # Print the help message

Contributing

Contributions to this project are welcome! If you have any suggestions, improvements, or bug fixes, feel free to submit a pull request.

License

This repository is licensed under the Apache License 2.0. Please review the license file provided in the repository for more information regarding the terms and conditions of the license.

Contact

  • Email:
    • [federico.bruzzone.i@gmail.com]
    • [federico.bruzzone@studenti.unimi.it]
  • GitHub:

No runtime deps