xexyl / jparse

JSON parser, library and tools written in C
3 stars 3 forks source link

rename jenc to byte2asciistr, avoid confusion about purpose #19

Closed lcn2 closed 2 months ago

lcn2 commented 2 months ago

We need to be more exact about the jenc[] does the purpose of struct encode, and what jstrencode -t and jstrdecode -t do, so we rename:

This is to avoid any potential confusion about the table performing any sort of true JSON encoding / decoding.

The table provides a trivial way to map an 8-bit byte into string of ASCII characters. We say "trivial" because the table converts 8-bit bytes in string of ASCII characters that is technically valid for encoded JSON strings even though they may not be canonical.

A valid Unicode symbol canonically should be encoded as 1 or more consecutive "\uHexHexHexHex" string combinations.

The "trivial" way to map 8-bit bytes into a string of ASCII characters that happens to not violate the so-called JSON specification. For example, the Unicode à character (U+00E0) is "hacked" into the ASCII string "\xe0", a 0xe0 byte followed by a NUL byte. In truth, the à character is passed along as an 8-bit binary value. The canonical encoding would be (probably) "\u00e0", a string of 6 ASCII characters.

The action of jstrencode -t and jstrdecode -t at present, only preformed a sanity test of the "trivial" way to map 8-bit bytes into a string of ASCII characters. And while the table remains in use, the table sanity test is mildly useful but should NOT be considered a test of of JSON encoding / decoding.

The jstrencode -t output, for example, now prints:

./jstrencode: Beginning jencchk test of the byte2asciistr table...
./jstrencode: ... passed byte2asciistr table test
./jstrencode: Beginning tests of JSON decode/encode functionality ...
./jstrencode: XXX - JSON encode/decode tests not yet written - XXX
./jstrencode: ... passed JSON encode/decode tests

When issue #13 is finally fixed, there may be useful tests that the -t might perform. If so, then the code it invokes should be updated accordingly.

xexyl commented 2 months ago

Thank you! I will have to stash my changes so I can merge.

I will read your comments tomorrow.