2 releases

0.0.1 Sep 15, 2020
0.0.0 Sep 15, 2020

#25 in #binary-representation

MIT license

14KB
145 lines

zwnbsp

Zero width character utilities

Crates.io Documentation

Installation

zwnbsp = "0.0.1"

Usage

Creating a HTML representation on ZWNBSP characters for "Hi!"

use zwnbsp::ZeroWidth;

fn main() {
    let zero_width = ZeroWidth::new("Hi!").unwrap().to_html();

    println!("{}", zero_width);
    // ‌​‌​​‌​​​‌‍‌​‌‌​‌​​‌‌‍‌​‌​​​​‌‌&#8205
}

Creating an Unicode representation on ZWNBSP characters for "Hi!"

use zwnbsp::ZeroWidth;

fn main() {
    let zero_width = ZeroWidth::new("Hi!").unwrap().to_unicode();

    println!("{}", zero_width);
    // ​​​​​​‌‍​​​​‌‍
}

How it works

For every conversion a binary representation of the ASCII text provided is done. This reduces the characters required to represent this data to 3 characters.

One character will represent the 0 value from the binary representations, the second will represent the 1 value from the binary representation and finally the third represents spaces to mark off the starting and the end of each binary set.

From ASCII to ZWNBSP

When performing a conversion from ASCII text to ZWNBSP, the ASCII text is first converted into its binary representation.

Given the text Hi! the result from encoding into binary would be 01001000 01101001 00100001.

Then, each value of the binary representation is replaced with its corresponding zero width character.

From ZWNBSP to ASCII

The process to convert ZWNBSP representations back to human readable ASCII is the "reverse" of converting from ASCII to ZWNBSP. The binary representation with replaced characters is then converted back to its binary representation in 1, 0 and , and then from binary representation to text.

Caveats

When converting some text back to ASCII you must have in mind that the corresponding values may not be the same as used by this crate.

Conversion Flowchart

The following flowchart explains the conversion from ASCII to ZWNBSP and from ZWNBSP back to ASCII.

Checking the values in Unicode

The example Creating an Unicode representation on ZWNBSP characters for "Hi!" contains the value in the comment that appears to be empty.

You can copy the complete snippet, go to diffchecker.com and paste it to find the hidden characters.

Release

To release a new version you must tag with git and push to the main branch.

git tag -a v0.1.0 -m "First Release"
git push origin main --follow-tags

Contributing

Every contribution to this project is welcome! Feel free to open a pull request or an issue.

License

Licensed under MIT License.

No runtime deps