From d8f33e938e38d9582ba7431bcb48e2f91867f7ec Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Jun 2016 21:56:00 +0100 Subject: 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. --- gentoobrowse-api/service/depend.cpp | 10 +++++----- 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(es->pattern->match(1)), // op *es->pattern->match(2), // category *es->pattern->match(3), // package - iuo(es->pattern->match(8)), // version - iuo(es->pattern->match(14)), // slot - split(es->pattern->match(17)) // use + iuo(es->pattern->match(5)), // version + iuo(es->pattern->match(11)), // slot + split(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); +} + -- cgit v1.2.3