Added C++ header-only library generator #197
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This pull request contains a generator (python3 script) to parse utf8prop.c and convert it to a constexpr C++ header-only library.
The resulting library is placed in the
utf8proc
namespace, andutf8proc_
prefixes are removed.Private entities are in the namespace
utf8proc::detail
.Why?
In C++, constexpr allows programmers to evaluate functions at compile-time (before the linker).
This is a big part of C++ meta-programming.
I could not find a constexpr library for Unicode, so here is my solution.
I used
utf8proc
as a basis because I do not want to implement these algorithms myself, and other libraries such asICU
are way too big for me to dive into and produce a generator in a fairly short period of time.Modifications on existing code?
When defined, it removes the functions that are calling malloc/realloc.
It was needed because such functions cannot be marked
constexpr
.static const char s[][3]
->static const char * const s[]
This does not modify the syntax anywhere, but it changes the string storage from
static storage to literal storage (needed in constexpr because static storage is not allowed).
All the tests of the C library passes correctly after these modifications.
License
The generation script is under the Boost Software License 1.0.
This is a more permissive license than the "expat" license:
The only requirement is to let the copyright notice inside the
gen_hpp.py
script.Nowhere else.