Skip to content

Commit

Permalink
better file regexing
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Aug 20, 2024
1 parent 470c9d6 commit 5a14d0d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mkn.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (c) 2022, Philip Deegan.
Copyright (c) 2024, Philip Deegan.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion mkn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: mkn
version: master
property:
DATE: 13-AUG-2024
DATE: 20-AUG-2024

parent: bin
mode: none
Expand Down
2 changes: 1 addition & 1 deletion src/maiken/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void sub_initializer(Application const& app, std::vector<YAML::Node> const& node
while (c) {
c = 0;
for (auto const& n : nodes) {
if (n[STR_NAME].Scalar() == profile){
if (n[STR_NAME].Scalar() == profile) {
process(n);
profile = n[STR_PARENT] ? Properties::RESOLVE(app, n[STR_PARENT].Scalar()) : "";
c = !profile.empty();
Expand Down
23 changes: 15 additions & 8 deletions src/regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

std::vector<std::string> maiken::Regexer::RESOLVE(std::string str) KTHROW(mkn::kul::Exception) {
std::vector<std::string> v;
auto posL = str.find("(");
auto posR = str.find(")");

auto const posL = str.find("(");
auto const posR = str.find(")");

if (posL == std::string::npos || posR == std::string::npos) return v;
if (str.size() > 1 && str.substr(0, 2) == "./") str = str.substr(2);
Expand All @@ -45,26 +46,32 @@ std::vector<std::string> maiken::Regexer::RESOLVE(std::string str) KTHROW(mkn::k
mkn::kul::Dir d(mkn::kul::env::CWD());
if (bits.size() > 1) d = mkn::kul::Dir(bits[0]);

str = bits[bits.size() - 1];

for (size_t i = 1; i < bits.size() - 1; i++) {
std::size_t i = 1;
for (; i < bits.size() - 1; i++) {
if (bits[i].find("(") != std::string::npos && bits[i].find(")") != std::string::npos) break;
d = d.join(bits[i]);
}

auto regexer = [&](auto items) {
str = bits[i];
std::string const prefix = str.substr(0, str.find("("));
str = str.substr(prefix.size(), str.size() - prefix.size());

auto regexer = [&](auto const& items) {
for (auto const& item : items) {
try {
std::string const real = item.real();
if (prefix.size() and real.find(prefix) == std::string::npos) continue;
std::regex re(str);
std::smatch match;
std::string subject(item.real());
if (std::regex_search(subject, match, re) && match.size() > 1) RESOLVE_REC(item.real(), v);
if (std::regex_search(real, match, re) && match.size() > 1) RESOLVE_REC(real, v);
} catch (std::regex_error& e) {
KEXIT(1, "Regex Failure:\n") << e.what();
}
}
};

regexer(d.files(/*recursive=*/true));

return v;
}

Expand Down

0 comments on commit 5a14d0d

Please sign in to comment.