generated from gdt050579/appcui-template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Gheorghita Mutu <gheorghitamutu@gmail.com>
- Loading branch information
1 parent
320732f
commit 4713383
Showing
8 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,3 @@ | ||
target_sources(GViewCore PRIVATE | ||
regex_wrapper.cpp | ||
) |
This file contains 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,55 @@ | ||
#include "../include/GView.hpp" | ||
|
||
#include <string> | ||
#include <re2/re2.h> | ||
|
||
namespace GView::Regex | ||
{ | ||
struct Context { | ||
bool isUnicode{ false }; | ||
bool isCaseSensitive{ false }; | ||
RE2 expression; | ||
}; | ||
|
||
bool Matcher::Init(std::string_view expression, bool isUnicode, bool isCaseSensitive) | ||
{ | ||
CHECK(this->context == nullptr, false, ""); | ||
|
||
RE2::Options options; | ||
options.set_case_sensitive(isCaseSensitive); | ||
|
||
absl::string_view asv{ expression.data(), expression.size() }; | ||
|
||
auto c = new Context{ | ||
.isUnicode = isUnicode, | ||
.isCaseSensitive = isCaseSensitive, | ||
.expression = RE2(asv, options), | ||
}; | ||
|
||
this->context = c; | ||
} | ||
|
||
Matcher::~Matcher() | ||
{ | ||
if (this->context != nullptr) { | ||
delete reinterpret_cast<Context*>(this->context); | ||
} | ||
} | ||
|
||
bool Matcher::Match(BufferView buffer, uint64& start, uint64& end) | ||
{ | ||
auto ctx = reinterpret_cast<Context*>(this->context); | ||
CHECK(ctx != nullptr, false, ""); | ||
CHECK(ctx->expression.ok(), false, ""); | ||
|
||
absl::string_view sv{ reinterpret_cast<const char*>(buffer.GetData()), buffer.GetLength() }; | ||
re2::StringPiece result; | ||
if (RE2::PartialMatch(sv, ctx->expression, &result)) { | ||
start = result.data() - sv.data(); | ||
end = start + result.size(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} // namespace GView::Regex |
This file contains 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 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 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