]> git.ipfire.org Git - thirdparty/systemd.git/commit
table: Improve mangling of JSON field names
authorAdrian Vovk <adrianvovk@gmail.com>
Wed, 3 Jul 2024 21:57:42 +0000 (17:57 -0400)
committerAdrian Vovk <adrianvovk@gmail.com>
Wed, 17 Jul 2024 18:15:43 +0000 (14:15 -0400)
commitc4cb49eb342bb347fb974eb55236d2eb3e565086
tree63280961c328ad348c129f8d516b4c66c7a3ba82
parentbf01601f11454cdf7f26c674893ccbca7c09a1ce
table: Improve mangling of JSON field names

First, when displaying JSON we convert dashes into underscores. We want
to avoid using dashes in JSON field names in new code, because some
JSON parsers don't support dashes very well.

Second, we make the first character of every word lower-case. This
better matches our JSON field name style, and makes the automatic
JSON name mangling a lot more useful for vertical tables, where fields
are given a display name. For example, "Foo Bar" would be converted into
"foo_bar" instead of "Foo_Bar", which much better matches our style.
We don't make the whole string lowercase to support cases like:
"fooBar" should stay as "fooBar".

Some situations don't behave quite perfectly, such as "Foo BarBaz" gets
converted into "foo_barBaz", or all-caps headings get mangled
incorrectly. In these situations, the JSON field should be overridden
manually. In most cases, or at least more cases than before, this
heuristic does good enough.
src/shared/format-table.c
src/shared/format-table.h
src/test/test-format-table.c