Back in May, the rather awesome imgui creator @ocornut asked the following;
And it got me thinking - why isn’t there a simple JSON reader/writer lib in the same vein as the stb_* libraries that performs a single call to malloc to encode the state? I couldn’t find one, so I decided to write my own.
I’m introducing json.h - my one header/one source json library that will parse a JSON source into a single allocation buffer, and also has functions to write out the minified version of the JSON, and a pretty print function (for human readable JSON).
Since my last post introducing utf8.h I’ve been frantically working on fleshing out the core utf8* functions to match the str* ones, and also listening to developer feedback!
Firstly, you can check out the one header C/C++ library here - utf8.h.
@daniel_collin suggested adding an ASCII only utf8casecmp, which has been added. I’m looking into extending this to support more of the characters in Unicode (the most obvious ones that I can understand are ASCII characters with accents).
I’ve been tinkering around with a new one header library (having been inspired by the awesome stb libraries that @nothings created), a utf8 string library https://github.com/sheredom/utf8.h.
The utf8.h header adds some new utf8* prefixed functions that match the str* functions you would find in string.h, except that they are all written for utf8 exclusively. For example, utf8len will return the number of utf8 codepoints found in the provided utf8 string.
I’m quite particular about how I word the variables that are exposed via my APIs. I always prefix pointers that I write to with out_*, my variables are always in C style this_is_my_variables_name and I try to be as descriptive as possible of what the type is actually going to be used for.
One thing that I tend to pay particular attention to is when I want to pass an array of items into a function.
Just about everyone has used the size_t type - and everybody and their grandmothers know what the type means of course! The usual answers I get to ‘tell me what size_t is without Googling it’ is;
It is the parameter type for malloc to allocate memory! It is a platform dependent 32/64 bit unsigned integer type! It is what size_type in all the C++ std template hell is! (ok I made this one up - but fuck me the size_type lark really annoys me in the std code.