string: add find_first variant taking a string#133
Open
Qwinci wants to merge 1 commit into
Open
Conversation
no92
requested changes
May 9, 2026
| if(_length < other._length) | ||
| return size_t(-1); | ||
|
|
||
| for(size_t i = 0; i < _length - other._length + 1; ++i) { |
Member
There was a problem hiding this comment.
Suggested change
| for(size_t i = 0; i < _length - other._length + 1; ++i) { | |
| for(size_t i = start_from; i <= _length - other._length; ++i) { |
| } | ||
|
|
||
| constexpr size_t find_first(basic_string_view other, size_t start_from = 0) const { | ||
| if(_length < other._length) |
Member
There was a problem hiding this comment.
We should probably also bounds-check the start_from argument:
if (start_from > _length) and if ((_length - start_from) < other._length) seem like reasonable checks?
Contributor
Author
There was a problem hiding this comment.
If start_from > _length || (_length - start_from) < other._length then i <= _length - other._length would not pass (unless other._length == 0 but in that case the inner loop wouldn't run at all and it would just end up returning i) so I don't think the checks are required correctness-wise, though I guess I can still add them for clarity?
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.
No description provided.