Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stellar/escape-bytes
Escapes bytes that are not printable ASCII characters.
https://github.com/stellar/escape-bytes
Last synced: 7 days ago
JSON representation
Escapes bytes that are not printable ASCII characters.
- Host: GitHub
- URL: https://github.com/stellar/escape-bytes
- Owner: stellar
- License: apache-2.0
- Created: 2023-11-30T10:43:06.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-07-27T06:10:39.000Z (4 months ago)
- Last Synced: 2024-10-31T12:12:59.077Z (13 days ago)
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# escape-bytes
Escapes bytes that are not printable ASCII characters.
The exact rules are:
- Nul is escaped as `\0`.
- Tab is escaped as `\t`.
- Line feed is escaped as `\n`.
- Carriage return is escaed as `\r`.
- Backslach is escaped as `\\`.
- Any character in the printable ASCII range `0x20`..=`0x7e` is not escaped.
- Any other character is hex escaped in the form `\xNN`.Intended for use where byte sequences are not valid ASCII or UTF-8 but need
to be stored in a semi-human readable form where only ASCII or UTF-8 are
permitted.### Examples
#### Escape
```rust
let str = b"hello\xc3world";
let escaped = escape_bytes::escape(str);
assert_eq!(escaped, br"hello\xc3world");
```#### Unescape
```rust
let escaped = br"hello\xc3world";
let unescaped = escape_bytes::unescape(escaped)?;
assert_eq!(unescaped, b"hello\xc3world");
```License: Apache-2.0