![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Dependency-free lexical formatters aimed at viewers: they re-indent a document so a human can read it, without validating it. More...
Functions | |
| N_STR * | n_pretty_js (const char *text) |
| Conservatively re-indent JavaScript (newlines at top-level braces and semicolons, two-space indent by brace depth). | |
| N_STR * | n_pretty_json (const char *text) |
| Reformat a JSON document with cJSON (parse + print). | |
| N_STR * | n_pretty_json_lenient (const char *text) |
| Re-indent a JSON document by punctuation alone, without parsing it. | |
| N_STR * | n_pretty_xml (const char *text) |
| Re-indent an XML or HTML document (one tag or text run per line). | |
Dependency-free lexical formatters aimed at viewers: they re-indent a document so a human can read it, without validating it.
Malformed input is reformatted on a best-effort basis; the formatters never crash on it.
Limits by design (these are viewers, not compilers):
All functions return a freshly allocated N_STR the caller must release with free_nstr(), or NULL when the input is NULL, empty, or does not look like the expected format.
| N_STR * n_pretty_js | ( | const char * | text | ) |
Conservatively re-indent JavaScript (newlines at top-level braces and semicolons, two-space indent by brace depth).
| text | The script text. NULL or empty input returns NULL. |
Definition at line 489 of file n_pretty.c.
References __n_assert, _js_newline(), _js_regex_keyword(), _js_regex_len(), _js_regex_possible(), _js_string_len(), _js_template_len(), _js_token(), _out_ch(), _out_finish(), JS_STATE::at_line_start, PRETTY_OUT::buf, Free, JS_STATE::indent, JS_STATE::kw_regex, JS_STATE::last_sig, JS_STATE::o, and JS_STATE::pending_space.
Referenced by main().
| N_STR * n_pretty_json | ( | const char * | text | ) |
Reformat a JSON document with cJSON (parse + print).
| text | The JSON text. NULL, empty, or non-JSON input returns NULL. |
Definition at line 89 of file n_pretty.c.
References __n_assert, char_to_nstr_nocopy(), LOG_ERR, and n_log.
Referenced by main().
| N_STR * n_pretty_json_lenient | ( | const char * | text | ) |
Re-indent a JSON document by punctuation alone, without parsing it.
String literals are copied verbatim, containers open and close a level, and each comma ends a line, so a document cJSON rejects (truncated, trailing comma, concatenated values) still becomes readable.
| text | The JSON text. NULL or empty input returns NULL. |
Definition at line 123 of file n_pretty.c.
References __n_assert, _jsonl_lead(), _jsonl_newline(), _out_ch(), _out_finish(), _out_mem(), PRETTY_OUT::buf, and Free.
Referenced by main().
| N_STR * n_pretty_xml | ( | const char * | text | ) |
Re-indent an XML or HTML document (one tag or text run per line).
| text | The markup text. NULL, empty, or input whose first non-whitespace character is not '<' returns NULL. |
Definition at line 286 of file n_pretty.c.
References __n_assert, _emit_line(), _emit_trimmed(), _find_tag_end(), _name_in_list(), _out_finish(), _stristr(), _tag_name(), PRETTY_OUT::buf, Free, PRETTY_RAWTEXT_ELEMENTS, PRETTY_TAG_NAME_MAX, and PRETTY_VOID_ELEMENTS.
Referenced by main().