summaryrefslogtreecommitdiffhomepage
path: root/README.md
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-04 12:15:59 +0200
committerGitHub <noreply@github.com>2021-05-04 12:15:59 +0200
commit776dc9e3166dfc3735bd72be3acd26ebc6a591f5 (patch)
treeff0968c366537455aa1d7bfc42dff81549016e31 /README.md
parent02629b84de23bdc5896ac4b357e2f16dfb3996ec (diff)
parentc4d1648ca6c3ac005b75c3b3b0bb79e664bead75 (diff)
Merge pull request #6 from jow-/printf-improvements
String format improvements
Diffstat (limited to 'README.md')
-rw-r--r--README.md20
1 files changed, 19 insertions, 1 deletions
diff --git a/README.md b/README.md
index 1253cc9..7ceb8df 100644
--- a/README.md
+++ b/README.md
@@ -898,7 +898,11 @@ libc's `printf()` implementation, namely it allows the `d`, `i`, `o`, `u`, `x`,
`X`, `e`, `E`, `f`, `F`, `g`, `G`, `c` and `s` conversions.
Additionally, an ucode specific `J` format is implemented, which causes the
-corresponding value to be formatted as JSON string.
+corresponding value to be formatted as JSON string. By prefixing the `J` format
+letter with a precision specifier, the resulting JSON output will be pretty
+printed. A precision of `0` will use tabs for indentation, any other positive
+precision will use that many spaces for indentation while a negative or omitted
+precision specifier will turn off pretty printing.
Other format specifiers such as `n` or `z` are not accepted and returned
verbatim. Format specifiers including `*` and `$` directives are rejected as
@@ -911,6 +915,20 @@ well.
printf("%c%c%c\n", 65, 98, 99); // Abc
printf("%g\n", 10 / 3.0); // 3.33333
printf("%J", [1,2,3]); // [ 1, 2, 3 ]
+
+ printf("%.J", [1,2,3]);
+ // [
+ // 1,
+ // 2,
+ // 3
+ // ]
+
+ printf("%.2J", [1,2,3]);
+ // [
+ // 1,
+ // 2,
+ // 3
+ // ]
%}
```