Skip to content

string: add find_first variant taking a string#133

Open
Qwinci wants to merge 1 commit into
managarm:masterfrom
Qwinci:master
Open

string: add find_first variant taking a string#133
Qwinci wants to merge 1 commit into
managarm:masterfrom
Qwinci:master

Conversation

@Qwinci
Copy link
Copy Markdown
Contributor

@Qwinci Qwinci commented May 9, 2026

No description provided.

Comment thread include/frg/string.hpp Outdated
if(_length < other._length)
return size_t(-1);

for(size_t i = 0; i < _length - other._length + 1; ++i) {
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.

Suggested change
for(size_t i = 0; i < _length - other._length + 1; ++i) {
for(size_t i = start_from; i <= _length - other._length; ++i) {

Comment thread include/frg/string.hpp
}

constexpr size_t find_first(basic_string_view other, size_t start_from = 0) const {
if(_length < other._length)
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.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

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