Author: jkupec Date: Mon Apr 7 21:22:53 2008 New Revision: 9439 URL: http://svn.opensuse.org/viewcvs/zypp?rev=9439&view=rev Log: - enable glob matching + test case Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc trunk/libzypp/zypp/PoolQuery.cc trunk/libzypp/zypp/PoolQuery.h Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=9439&r1=9438&r2=9439&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original) +++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Mon Apr 7 21:22:53 2008 @@ -192,6 +192,37 @@ BOOST_CHECK(q1.size() == 5); } +// use globs +BOOST_AUTO_TEST_CASE(pool_query_9) +{ + cout << "****9****" << endl; + PoolQuery q; + q.addString("z?p*"); + q.addAttribute(sat::SolvAttr::name); + q.setMatchGlob(); + + std::for_each(q.begin(), q.end(), &result_cb); + BOOST_CHECK(q.size() == 11); + + cout << endl; + + PoolQuery q1; + q1.addString("*zypp*"); + q1.addAttribute(sat::SolvAttr::name); + q1.setMatchGlob(); + + std::for_each(q1.begin(), q1.end(), &result_cb); + BOOST_CHECK(q1.size() == 28); + + // should be the same as above + PoolQuery q2; + q2.addString("zypp"); + q2.addAttribute(sat::SolvAttr::name); + + BOOST_CHECK(q2.size() == 28); +} + +// save/load query BOOST_AUTO_TEST_CASE(pool_query_save_restore) { #warning CAN NOT USE A FIX SOLV FILE Modified: trunk/libzypp/zypp/PoolQuery.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=9439&r1=9438&r2=9439&view=diff ============================================================================== --- trunk/libzypp/zypp/PoolQuery.cc (original) +++ trunk/libzypp/zypp/PoolQuery.cc Mon Apr 7 21:22:53 2008 @@ -52,7 +52,7 @@ Impl() : _flags( SEARCH_ALL_REPOS | SEARCH_NOCASE | SEARCH_SUBSTRING ) , _status_flags(ALL) - , _match_word(false), _use_wildcards(false) + , _match_word(false) , _require_all(false) , _compiled(false) {} @@ -127,7 +127,6 @@ int _status_flags; bool _match_word; - bool _use_wildcards; bool _require_all; @@ -301,26 +300,15 @@ if (container.size() == 1) { - rstr = *container.begin(); + if (_match_word) + return ".*" + WB + *container.begin() + WB + ".*"; - if (!_use_wildcards && ((_flags & SEARCH_STRINGMASK) != SEARCH_REGEX)) - return rstr; - - if (_use_wildcards) - { - rstr = wildcards2regex(rstr); - - if (_flags & SEARCH_STRING) // match exact - rstr = "^" + rstr + "$"; - } - - rstr = ".*" + WB + rstr + WB + ".*"; - - return rstr; + return *container.begin(); } // multiple strings + bool _use_wildcards = (_flags & SEARCH_STRINGMASK) == SEARCH_GLOB; vector<string>::const_iterator it = container.begin(); string tmp; @@ -649,18 +637,19 @@ void PoolQuery::setMatchSubstring() - { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_SUBSTRING; } + { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_SUBSTRING; } void PoolQuery::setMatchExact() - { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_STRING; } + { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_STRING; } void PoolQuery::setMatchRegex() - { _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_REGEX; } + { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_REGEX; } + void PoolQuery::setMatchGlob() + { _pimpl->_flags |= (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_GLOB; } void PoolQuery::setMatchWord() { _pimpl->_match_word = true; _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRINGMASK) | SEARCH_REGEX; } - void PoolQuery::setFlags(int flags) { _pimpl->_flags = flags; } Modified: trunk/libzypp/zypp/PoolQuery.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.h?rev=9439&r1=9438&r2=9439&view=diff ============================================================================== --- trunk/libzypp/zypp/PoolQuery.h (original) +++ trunk/libzypp/zypp/PoolQuery.h Mon Apr 7 21:22:53 2008 @@ -213,20 +213,14 @@ /** Set to match exact string instead of substring.*/ void setMatchExact(); - /** Set to use the query strings as regexes */ - void setMatchRegex(); /** Set to substring (the default). */ void setMatchSubstring(); + /** Set to match globs. */ + void setMatchGlob(); + /** Set to use the query strings as regexes */ + void setMatchRegex(); /** Set to match words (uses regex) */ void setMatchWord(); - - /** - * If true, convert * and ? to correspondent regex equivalent, otherwise - * shield wildcards from being interpreted like regex control chars (if - * SEARCH_REGEX is set) - */ - void setUseWildcards(const bool value = true); - //void setLocale(const Locale & locale); //@} -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org