Skip to content

Commit

Permalink
Merge 65d2f91 into f582eaf
Browse files Browse the repository at this point in the history
  • Loading branch information
xgcssch committed Mar 13, 2021
2 parents f582eaf + 65d2f91 commit a9cffd0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/bpstd/detail/string_view.inl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace bpstd {
}

const auto offset = pos;
const auto increments = size() - v.size();
const auto increments = size() - v.size() - offset;

for (auto i = 0u; i <= increments; ++i) {
const auto j = i + offset;
Expand Down
2 changes: 1 addition & 1 deletion single_include/bpstd/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ namespace bpstd {
}

const auto offset = pos;
const auto increments = size() - v.size();
const auto increments = size() - v.size() - offset;

for (auto i = 0u; i <= increments; ++i) {
const auto j = i + offset;
Expand Down
17 changes: 17 additions & 0 deletions tests/bpstd/string_view.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,23 @@ TEST_CASE("string_view::find", "[operations]")
REQUIRE( result == 0u );
}
}
SECTION("Argument is string, offset in string, no match")
{
bpstd::string_view s1 = "01234567890ABCDEFGHIJ";
bpstd::string_view s2 = "01";

auto result = s1.find(s2);
SECTION("prefix find ok")
{
REQUIRE(result != bpstd::string_view::npos);
REQUIRE(s1.size() > 10);
}
auto result1 = s1.find(s2, 10);
SECTION("nonmatching substring")
{
REQUIRE(result1 == bpstd::string_view::npos);
}
}
}
}

Expand Down

0 comments on commit a9cffd0

Please sign in to comment.