Skip to content

avoid using impl in error_printer example #268

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

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

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Apr 1, 2025

What does this change do?

Replaced access to toml::impl::control_char_escapes with manual handling of control characters, in print_string.

Would ease a possible future replacement of #include <toml++/toml.hpp> with import tomplplusplus (because toml::impl is not exported).

Is it related to an existing bug report or feature request?

  • I've read CONTRIBUTING.md
  • I've rebased my changes against the current HEAD of origin/master (if necessary)
  • I've added new test cases to verify my change
  • I've regenerated toml.hpp (how-to)
  • I've updated any affected documentation
  • I've rebuilt and run the tests with at least one of:
    • Clang 8 or higher
    • GCC 8 or higher
    • MSVC 19.20 (Visual Studio 2019) or higher
  • I've added my name to the list of contributors in README.md

Replaced access to `toml::impl::control_char_escapes` with manual handling of control characters, in `print_string`.

Would ease a possible future replacement of `#include <toml++/toml.hpp>` with `import tomplplusplus` (because `toml::impl` is not exported).
@N-Dekker N-Dekker force-pushed the avoid-impl-in-error_printer-example branch from 9ecb963 to ac1644a Compare April 1, 2025 10:54
Comment on lines +117 to +123
: (c == '\a') ? "\\a"sv
: (c == '\b') ? "\\b"sv
: (c == '\f') ? "\\f"sv
: (c == '\n') ? "\\n"sv
: (c == '\r') ? "\\r"sv
: (c == '\t') ? "\\t"sv
: (c == '\v') ? "\\v"sv
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: Two simple escape sequences, \a (0x07) and \v (0x0B), are not in toml::impl::control_char_escapes:

inline constexpr std::string_view control_char_escapes[] =
{
"\\u0000"sv,
"\\u0001"sv,
"\\u0002"sv,
"\\u0003"sv,
"\\u0004"sv,
"\\u0005"sv,
"\\u0006"sv,
"\\u0007"sv,
"\\b"sv,
"\\t"sv,
"\\n"sv,
"\\u000B"sv,
"\\f"sv,
"\\r"sv,

I found them at https://eel.is/c++draft/lex.ccon#nt:simple-escape-sequence-char saying:

simple-escape-sequence-char: one of
  '  "  ?  \ a  b  f  n  r  t  v

Would it be worth adding these two to toml::impl::control_char_escapes as well? Honestly it doesn't matter much to me. Just asking 😃

@N-Dekker N-Dekker marked this pull request as ready for review April 1, 2025 11:16
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