diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-02 21:56:00 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-06-02 21:56:00 +0100 |
commit | 9e86c371fff17ee2dfac886646a91d1d8abb7df3 (patch) | |
tree | 5d918f6f91f832a0d7628a66fedd356d418ff871 | |
parent | Support enabling/disabling various parts of the update process. (diff) | |
download | gentoobrowse-api-9e86c371fff17ee2dfac886646a91d1d8abb7df3.tar.bz2 gentoobrowse-api-9e86c371fff17ee2dfac886646a91d1d8abb7df3.tar.xz gentoobrowse-api-9e86c371fff17ee2dfac886646a91d1d8abb7df3.zip |
Simplify the regex used match package names in dependencies.
Uses non-greedy matching for a wider scope of things and anchors the
match to whitespace or end of string... adds yet another test case.
-rw-r--r-- | gentoobrowse-api/service/depend.cpp | 10 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testDepend.cpp | 11 |
2 files changed, 16 insertions, 5 deletions
diff --git a/gentoobrowse-api/service/depend.cpp b/gentoobrowse-api/service/depend.cpp index 6851eea..3d325d7 100644 --- a/gentoobrowse-api/service/depend.cpp +++ b/gentoobrowse-api/service/depend.cpp @@ -9,10 +9,10 @@ Gentoo::Utils::Lexer::PatternPtr Or_End(Gentoo::Utils::Lexer::regex("\\s*\\)\\s* Gentoo::Utils::Lexer::PatternPtr AtomSpec(Gentoo::Utils::Lexer::regex("\\s*" "([[:punct:]]+)?" // op "([[:alnum:]-]+)\\/" // cat - "([[:alnum:]]*((-?[[:alpha:]_+]+[[:digit:]]+)|[[:alpha:]_+]|(-[[:alpha:]_+]))+)" // package + "([^ ]+)" // package "(-([0-9][.0-9]*[[:alpha:]]?\\*?((_(alpha|beta|pre|rc|p))?[[:digit:]]*)*(-r[[:digit:]]+)?))?" // version "(:([^/ []+(\\/[^ []+)?))?" // slot - "(\\[([^]]+)\\])?\\s*", G_REGEX_OPTIMIZE)); // use + "(\\[([^]]+)\\])?(\\s+|$)", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_UNGREEDY))); // use const std::string InWhen("InWhen"); const std::string InOr("InOr"); @@ -68,9 +68,9 @@ namespace Portage { iuo<std::string>(es->pattern->match(1)), // op *es->pattern->match(2), // category *es->pattern->match(3), // package - iuo<std::string>(es->pattern->match(8)), // version - iuo<std::string>(es->pattern->match(14)), // slot - split<std::string>(es->pattern->match(17)) // use + iuo<std::string>(es->pattern->match(5)), // version + iuo<std::string>(es->pattern->match(11)), // slot + split<std::string>(es->pattern->match(14)) // use )); } }); } diff --git a/gentoobrowse-api/unittests/testDepend.cpp b/gentoobrowse-api/unittests/testDepend.cpp index 646b593..942dbaf 100644 --- a/gentoobrowse-api/unittests/testDepend.cpp +++ b/gentoobrowse-api/unittests/testDepend.cpp @@ -308,3 +308,14 @@ BOOST_AUTO_TEST_CASE( thisThing ) BOOST_REQUIRE_EQUAL(*ds[0]->version, "1.0"); } +BOOST_AUTO_TEST_CASE( thatThing ) +{ + auto ds = Portage::Utils::Depend::parse("!sys-firmware/iwl3160-7260-bt-ucode"); + BOOST_REQUIRE_EQUAL(ds.size(), 1); + BOOST_REQUIRE(ds[0]->op); + BOOST_REQUIRE_EQUAL(*ds[0]->op, "!"); + BOOST_REQUIRE_EQUAL(ds[0]->category, "sys-firmware"); + BOOST_REQUIRE_EQUAL(ds[0]->package, "iwl3160-7260-bt-ucode"); + BOOST_REQUIRE(!ds[0]->version); +} + |