Skip to content

Commit

Permalink
Lakos rule: remove noexcept because of narrow contract
Browse files Browse the repository at this point in the history
  • Loading branch information
cschreib committed May 7, 2024
1 parent d91b154 commit 909303e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/snitch/snitch_string_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ constexpr small_string<N> resize_or_truncate(const small_string<M>& str) noexcep
SNITCH_EXPORT [[nodiscard]] bool replace_all(
small_string_span string, std::string_view pattern, std::string_view replacement) noexcept;

// Requires: replacement.length() > pattern.length()
SNITCH_EXPORT [[nodiscard]] bool escape_all_or_truncate(
small_string_span string, std::string_view pattern, std::string_view replacement) noexcept;
small_string_span string, std::string_view pattern, std::string_view replacement);

SNITCH_EXPORT [[nodiscard]] std::size_t
find_first_not_escaped(std::string_view str, char c) noexcept;
Expand Down
4 changes: 2 additions & 2 deletions src/snitch_string_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ bool replace_all(
}

bool escape_all_or_truncate(
small_string_span string, std::string_view pattern, std::string_view replacement) noexcept {
small_string_span string, std::string_view pattern, std::string_view replacement) {

if (replacement.size() <= pattern.size()) {
terminate_with("escape_all() requires a replacement that is longer than the pattern");
assertion_failed("escape_all() requires a replacement that is longer than the pattern");
}

const std::size_t char_diff = replacement.size() - pattern.size();
Expand Down
9 changes: 9 additions & 0 deletions tests/runtime_tests/string_utility.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "testing.hpp"
#include "testing_assertions.hpp"

#include <cmath>

Expand Down Expand Up @@ -843,6 +844,14 @@ TEST_CASE("escape_all_or_truncate", "[utility]") {
"abaca", "abacaabcdefghijklmqrst", "abcdefghijklmnopqrstabcdefghijklmnopqrst") ==
e{"abaca", true});
}

SECTION("with replacement smaller than pattern") {
assertion_exception_enabler enabler;

CHECK_THROWS_WHAT(
escape<5>("abaca", "aa", "a"), assertion_exception,
"requires a replacement that is longer than the pattern");
}
}

TEST_CASE("is_match", "[utility]") {
Expand Down

0 comments on commit 909303e

Please sign in to comment.