Add C++20 u8 variants of string access methods (#2731)#2786
Open
AlbertoFVisconti wants to merge 1 commit into
simdjson:mastersimdjson/simdjson:masterfrom
AlbertoFVisconti:feature/add-u8-string-accessAlbertoFVisconti/simdjson:feature/add-u8-string-accessCopy head branch name to clipboard
Open
Add C++20 u8 variants of string access methods (#2731)#2786AlbertoFVisconti wants to merge 1 commit intosimdjson:mastersimdjson/simdjson:masterfrom AlbertoFVisconti:feature/add-u8-string-accessAlbertoFVisconti/simdjson:feature/add-u8-string-accessCopy head branch name to clipboard
AlbertoFVisconti wants to merge 1 commit into
simdjson:mastersimdjson/simdjson:masterfrom
AlbertoFVisconti:feature/add-u8-string-accessAlbertoFVisconti/simdjson:feature/add-u8-string-accessCopy head branch name to clipboard
Conversation
Member
|
Let us run tests! |
AlbertoFVisconti
force-pushed
the
feature/add-u8-string-access
branch
from
July 21, 2026 17:12
3e8e741 to
1f5c907
Compare
Author
|
I noticed the CI checks failed on the noexcept builds. I changed .value(), which throws an exception, for .value_unsafe() and now it should work! |
lemire
reviewed
Jul 22, 2026
| if (res.error()) { | ||
| return res.error(); | ||
| } | ||
| return std::u8string_view(reinterpret_cast<const char8_t*>(res.value_unsafe().data()), res.value_unsafe().size()); |
Member
There was a problem hiding this comment.
Try something like this...
std::string_view v;
SIMDJSON_TRY(get_string().get(v));I discourage the use of value_unsafe (as the name suggests, it is error prone).
Author
There was a problem hiding this comment.
thanks for the feedback! I have updated it with the macro and pushed, i have tested locally with noexcept so it should work.
AlbertoFVisconti
force-pushed
the
feature/add-u8-string-access
branch
from
July 22, 2026 16:04
1f5c907 to
7c97878
Compare
Member
|
@AlbertoFVisconti I have removed the claim that it removes #2731 because it is only a partial step, for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Short title (summary):
Description
This PR adds C++20
char8_tsupport by introducing theget_u8string()method todom::elementandsimdjson_result<dom::element>. This allows C++20 users to directly retrieve valid UTF-8 strings asstd::u8string_viewusing a safereinterpret_castwithout needing to cast it manually. The implementations are strictly guarded by#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811Lto ensure zero impact on C++11/C++17 builds.Type of change
How to verify / test
u8string_value()test case totests/dom/basictests.cppto verify correct parsing and casting behavior.SIMDJSON_CXX_STANDARD=17correctly ignores the macro guards.SIMDJSON_CXX_STANDARD=20compiles the new code, executes the test, and passes all assertions.Checklist before submitting