-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add optional RE2 regex engine support #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
49269bc
feat: add google/re2 and abseil-cpp dependencies
Copilot d625ab2
fix: enable ABSL_ENABLE_INSTALL to resolve re2 export set error
Copilot eee7191
build: pin abseil to stable 20240722.0
Copilot 1dd92dd
build: avoid sanitizer breakage with gcc 14 in standalone builds
Copilot 63e588c
chore: fix sanitizer skip status message wording
Copilot 907298c
fix: move sanitizer flags after external deps to avoid Abseil GCC+ASa…
Copilot e9d7ecc
feat: add RegexStrategy with StdRegexStrategy and Re2RegexStrategy im…
Copilot 5ce2030
refactor: remove unused pattern members, add RE2 error handling and i…
Copilot a29ca14
refactor: split RegexStrategy into separate files per class, use type…
Copilot 89aae22
feat: make RE2 optional via CCR_USE_RE2, add RegexStrategyFactory
Copilot 54f7af7
feat: update RegexStrategy::Match to return MatchGroup with positions…
Copilot bf801be
refactor: remove matched bool from MatchGroup; use optional<MatchGrou…
Copilot c38ec6b
refactor: update Match method signatures to use Matches type; adjust …
daantimmer a985e36
feat: add conditional compilation for RE2 support in CMakeLists.txt
daantimmer 9410cea
fix: rewrite float regex to be RE2-compatible, removing positive look…
Copilot 16b9446
refactor: update Match method parameters to use const references; imp…
daantimmer 3aa5c08
ci: add ubuntu no-re2 variant to test matrix
Copilot a7c7ffb
ci: extend no-re2 test matrix to windows and macos
Copilot d8edcca
ci: simplify no-re2 matrix by adding preset_suffix entry instead of i…
Copilot 37f8bba
refactor: simplify Re2RegexStrategy by removing unique_ptr and updati…
daantimmer 977ef3b
Gate find_package(absl) and find_package(re2) on CCR_USE_RE2
Copilot 412b9ea
fix: construct RE2 with explicit absl::string_view
Copilot 928f84e
docs: document cmake options and fetch deps usage
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
cucumber_cpp/library/cucumber_expression/Re2RegexStrategy.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include "cucumber_cpp/library/cucumber_expression/Re2RegexStrategy.hpp" | ||
| #include "absl/strings/string_view.h" | ||
| #include "cucumber_cpp/library/cucumber_expression/RegexStrategy.hpp" | ||
| #include <cstddef> | ||
| #include <optional> | ||
| #include <re2/re2.h> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| namespace cucumber_cpp::library::cucumber_expression | ||
| { | ||
| Re2RegexStrategy::Re2RegexStrategy(std::string_view pattern) | ||
| : re2{ absl::string_view{ pattern.data(), pattern.size() } } | ||
| { | ||
| if (!re2.ok()) | ||
| throw std::invalid_argument(re2.error()); | ||
| } | ||
|
daantimmer marked this conversation as resolved.
|
||
|
|
||
| std::optional<Matches> Re2RegexStrategy::Match(std::string_view text) const | ||
| { | ||
| const int nCaptures = re2.NumberOfCapturingGroups(); | ||
| const int nSubmatch = nCaptures + 1; | ||
| std::vector<absl::string_view> submatch(static_cast<std::size_t>(nSubmatch)); | ||
|
|
||
| if (!re2.Match(text, 0, static_cast<int>(text.size()), RE2::UNANCHORED, submatch.data(), nSubmatch)) | ||
| return std::nullopt; | ||
|
|
||
| Matches result; | ||
| result.reserve(static_cast<std::size_t>(nSubmatch)); | ||
| for (const auto& piece : submatch) | ||
| { | ||
| if (piece.data() == nullptr) | ||
| result.emplace_back(std::nullopt); | ||
| else | ||
| { | ||
| const auto start = static_cast<std::size_t>(piece.data() - text.data()); | ||
| result.emplace_back(MatchGroup{ | ||
| .value = std::string(piece), | ||
| .start = start, | ||
| .end = start + piece.size(), | ||
| }); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
cucumber_cpp/library/cucumber_expression/Re2RegexStrategy.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef CUCUMBER_EXPRESSION_RE2REGEXSTRATEGY_HPP | ||
| #define CUCUMBER_EXPRESSION_RE2REGEXSTRATEGY_HPP | ||
|
|
||
| #include "cucumber_cpp/library/cucumber_expression/RegexStrategy.hpp" | ||
| #include "re2/re2.h" | ||
| #include <optional> | ||
| #include <string_view> | ||
|
|
||
| namespace cucumber_cpp::library::cucumber_expression | ||
| { | ||
| struct Re2RegexStrategy : RegexStrategy | ||
| { | ||
| explicit Re2RegexStrategy(std::string_view pattern); | ||
|
|
||
| [[nodiscard]] std::optional<Matches> Match(std::string_view text) const override; | ||
|
|
||
| private: | ||
| re2::RE2 re2; | ||
| }; | ||
| } | ||
|
|
||
| #endif |
30 changes: 30 additions & 0 deletions
30
cucumber_cpp/library/cucumber_expression/RegexStrategy.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef CUCUMBER_EXPRESSION_REGEXSTRATEGY_HPP | ||
| #define CUCUMBER_EXPRESSION_REGEXSTRATEGY_HPP | ||
|
|
||
| #include <cstddef> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| namespace cucumber_cpp::library::cucumber_expression | ||
| { | ||
| struct MatchGroup | ||
| { | ||
| std::string value; | ||
| std::size_t start; | ||
| std::size_t end; | ||
| }; | ||
|
|
||
| using Matches = std::vector<std::optional<MatchGroup>>; | ||
|
|
||
| struct RegexStrategy | ||
| { | ||
| RegexStrategy() = default; | ||
| virtual ~RegexStrategy() = default; | ||
|
|
||
| [[nodiscard]] virtual std::optional<Matches> Match(std::string_view text) const = 0; | ||
| }; | ||
| } | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.