pub fn zalgo_encode(string: &str) -> Result<String, EncodeError>
Expand description
Takes in a string slice that consists of only printable ACII and newline characters and encodes it into a single grapheme cluster using a reversible encoding scheme.
The resulting string is a single unicode grapheme cluster and should
only take up a single character space horizontally when displayed
(though this can vary between platforms depending on how they deal with unicode).
The resulting string will be ~2 times larger than the original in terms of bytes, and it
can be decoded to recover the original string with zalgo_decode
.
§Errors
Returns an error if the input contains a byte that does not correspond to a printable ASCII character or newline. Notably this means that this function can not encode tab or carriage return characters. Carriage returns are present in e.g. line endings on Windows.
§Example
Basic usage:
assert_eq!(zalgo_encode("Zalgo")?, "É̺͇͌͏");
Can not encode non-ASCII characters or ASCII control characters except newlines:
assert!(zalgo_encode("Windows line ending: \r\n").is_err());
assert!(zalgo_encode("Zålgö").is_err());