Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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)#2786
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

@AlbertoFVisconti

@AlbertoFVisconti AlbertoFVisconti commented Jul 21, 2026

Copy link
Copy Markdown

Short title (summary):

Description

  • What did you change and why? (1-3 sentences)
    This PR adds C++20 char8_t support by introducing the get_u8string() method to dom::element and simdjson_result<dom::element>. This allows C++20 users to directly retrieve valid UTF-8 strings as std::u8string_view using a safe reinterpret_cast without needing to cast it manually. The implementations are strictly guarded by #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L to ensure zero impact on C++11/C++17 builds.

Type of change

  • Bug fix
  • Optimization
  • [ x] New feature
  • Refactor / cleanup
  • Documentation / tests
  • Other (please describe):

How to verify / test

  • Added the u8string_value() test case to tests/dom/basictests.cpp to verify correct parsing and casting behavior.
  • Verified locally that building with SIMDJSON_CXX_STANDARD=17 correctly ignores the macro guards.
  • Verified locally that building with SIMDJSON_CXX_STANDARD=20 compiles the new code, executes the test, and passes all assertions.

Checklist before submitting

  • [x ] I added/updated tests covering my change (if applicable)
  • [ x] Code builds locally and passes my check
  • Documentation / README updated if needed
  • [x ] Commits are atomic and messages are clear
  • [x ] I linked the related issue (if applicable)

@lemire

lemire commented Jul 21, 2026

Copy link
Copy Markdown
Member

Let us run tests!

@AlbertoFVisconti
AlbertoFVisconti force-pushed the feature/add-u8-string-access branch from 3e8e741 to 1f5c907 Compare July 21, 2026 17:12
@AlbertoFVisconti

Copy link
Copy Markdown
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!

Comment thread include/simdjson/dom/element-inl.h Outdated
if (res.error()) {
return res.error();
}
return std::u8string_view(reinterpret_cast<const char8_t*>(res.value_unsafe().data()), res.value_unsafe().size());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback! I have updated it with the macro and pushed, i have tested locally with noexcept so it should work.

@AlbertoFVisconti
AlbertoFVisconti force-pushed the feature/add-u8-string-access branch from 1f5c907 to 7c97878 Compare July 22, 2026 16:04
@lemire

lemire commented Jul 23, 2026

Copy link
Copy Markdown
Member

@AlbertoFVisconti I have removed the claim that it removes #2731 because it is only a partial step, for now.

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.