Skip to main content

Module text_tools

Module text_tools 

Source
Expand description

Text tools (PLAN_v0.3.0 P4): JSON format, minify and validate with our own tokenizer, Base64 and URL (percent) encoding, and MD5, SHA-1 and SHA-256 hashes.

The editing tools work on every non-empty selection, or on the whole document when nothing is selected; each run is one undo step. Without a selection, blank space at the start and end of the document is left out (a final line break stays where it is). Text is encoded and hashed as UTF-8 with the document’s line endings, so a whole UTF-8 document hashes like its file; decoded line breaks become the editor’s.

Structs§

Hashes
Hashes of some text, as lowercase hex.
InvalidJson
Where the JSON in a document stops being valid.
JsonError
Where a JSON text stops being valid, and why.

Enums§

Codec
A text encoding for Action::Encode and Action::Decode.

Constants§

MAX_FORMAT_DEPTH
Format JSON refuses deeper nesting (minifying and validating do not).

Functions§

base64_decode
Decodes Base64 in the standard or URL-safe alphabet. Spaces and line breaks are skipped and the = padding may be left out.
base64_encode
Base64 with the standard alphabet and = padding.
format_json
One member or element per line, each level indented by indent (a tab, or indent.width spaces). Key order, number text and strings are kept exactly; only the whitespace between tokens changes.
hash_selections
The hash tool’s text: the non-empty selections joined by line breaks (as a copy of them would be), or the whole document when nothing is selected. The flag says it was the whole document.
hashes
Hashes the UTF-8 bytes of text, with ending for every line break.
hex_decode
Reads pairs of hex digits, skipping blanks and line breaks.
hex_encode
Two upper-case hex digits per byte.
minify_json
The JSON with no whitespace between its tokens.
url_decode
Decodes %XX escapes; everything else, + included, is kept.
url_encode
Percent-encodes every byte except the RFC 3986 unreserved characters.
validate_json
Checks that text is one JSON value (with blank space around it).
validate_json_in
Checks the JSON in each selection, or the document when nothing is selected (Text Tools > Validate JSON). Not an edit.