Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added C++ header-only library generator #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J-Vernay
Copy link

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, and utf8proc_ 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 as ICU are way too big for me to dive into and produce a generator in a fairly short period of time.

Modifications on existing code?

  • Addition of a preprocessor command: UTF8PROC_NO_ALLOC.
    When defined, it removes the functions that are calling malloc/realloc.
    It was needed because such functions cannot be marked constexpr.
  • Enforcement of initialization of all variables (needed for constexpr).
  • Modification of an internal type: 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.

@J-Vernay J-Vernay changed the title Added HPP generator Added C++ header-only library generator Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant