Skip to content

Conversation

@N-Dekker
Copy link
Contributor

Commit text

When the specified line is empty, the returned string_view will still have a valid (non-null) data pointer. When the line number is out of range, the data pointer will be null.

What does this change do?

It documents the return value more specifically, when the specified line number is out of range, and when the line is empty. Allowing users to distinguish between those two cases more easily.

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

Pre-merge checklist

  • 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

When the specified line is empty, the returned `string_view` will still have a valid (non-null) data pointer. When the line number is out of range, the data pointer will be null.
@marzer
Copy link
Owner

marzer commented Feb 26, 2025

Hmmmn, that's not a particularly idiomatic usage of string views. Perhaps returning optional<string_view> might be more palatable? Given they're used elsewhere in the library already.

@N-Dekker
Copy link
Contributor Author

Ah, I see, thanks. I did not realize before that the use of the null-ness of a string_view appears controversial. But indeed, I understand from the discussion on string_view::is_null() that such a use case is discouraged. Even though the standard explicitly specifies that the data pointer of a default-constructed string_view is null 🤷

So I'm now considering to use optional<string_view>, as you suggest. To be continued...

@N-Dekker
Copy link
Contributor Author

@N-Dekker N-Dekker closed this Feb 27, 2025
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