Skip to content

Conversation

@trueqbit
Copy link

Originally i set out to correct a warning about snprintf() requiring an unsigned int when passed a char32_t.

So this PR fixes this warning and more:

  • It is better, or even the only correct approach, to use the documented underlying types of C++ Unicode character types for byte-based, arithmetic, or bitwise operations. These are defined to have at least the required bit size, as opposed to a fixed bit size. Also there are platforms where integral types of fixed bit size are unavailable. Specifically: char -> unsigned char, char8_t -> unsigned char, char16_t -> std::uint_least16_t, char32_t -> std::uint_least32_t.
  • Fixed a crash in json::basic_reader<>::match() due to accessing the character array past-the-end.
  • Fixed non-compiling json::basic_reader<>::match_any().
  • Replaced character-pointer logic in json::basic_reader<> with string_view functionality or iterator logic.

Additionally:

  • The CMake project was built with Linux in mind. I updated it so it works on Windows with Visual C++.
  • In addition, I added the compiler option to treat the warning about incorrect order of initialization of members as an error, which I found very useful in other codebases.

C++ unicode character types are defined as being equivalent to underlying types of at least N bits, so it's correct to use those, and improves platform-independency.
* replaced character-pointer logic with string_view functionality.
* corrected non-compiling `reader::match_any()`.
* simplified consumption loop.
@eteran
Copy link
Owner

eteran commented Nov 10, 2025

Fantastic! I'll take a look at this in a little bit and try to get it merged quickly.

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.

2 participants