[Aptitude-svn-commit] r3703 - in branches/aptitude-0.3/aptitude: . src/generic

Daniel Burrows dburrows at costa.debian.org
Fri Aug 5 02:43:08 UTC 2005


Author: dburrows
Date: Fri Aug  5 02:43:05 2005
New Revision: 3703

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/matchers.cc
   branches/aptitude-0.3/aptitude/src/generic/matchers.h
Log:
Allow multi-character terminating strings.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Aug  5 02:43:05 2005
@@ -1,5 +1,14 @@
 2005-08-04  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/matchers.cc, src/generic/matchers.h:
+
+	  Change the parse_pattern interface again (and make it less
+	  efficient) in order to allow arbitrary (possibly
+	  multi-character) strings to be used as terminators.  In
+	  particular, this will mean I can get the patterns grouping
+	  policy (with its "=>" delimiter) working properly without
+	  comprimising on the syntax.
+
 	* src/generic/util.cc, src/generic/util.h:
 
 	  Write generic (inefficient) code to produce string objects

Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.cc	Fri Aug  5 02:43:05 2005
@@ -1493,6 +1493,36 @@
   }
 };
 
+// Check for terminators.  Not terribly efficient, but I expect under
+// 3 terminators in any interesting usage (more than that and I really
+// should force yacc to do my bidding)
+bool terminate(const string::const_iterator &start,
+	       const string::const_iterator &end,
+	       const vector<const char *> &terminators)
+{
+  for(vector<const char *>::const_iterator i = terminators.begin();
+      i != terminators.end(); ++i)
+    {
+      string::const_iterator j1 = start;
+      const char *j2 = *i;
+      bool matches = true;
+
+      while(j1 != end && *j2 != 0 && matches)
+	{
+	  if(*j1 != *j2)
+	    matches=false;
+
+	  ++j1;
+	  ++j2;
+	}
+
+      if(matches)
+	return true;
+    }
+
+  return false;
+}
+
 // Parses a dependency type.  Returns (ick) -1 if the type is not
 // recognized.
 pkgCache::Dep::DepType parse_deptype(const string &s)
@@ -1515,7 +1545,7 @@
 
 pkg_matcher *parse_condition_list(string::const_iterator &start,
 				  const string::const_iterator &end,
-				  const char *terminators,
+				  const vector<const char *> &terminators,
 				  bool match_descriptions);
 
 // Returns a substring up to the first metacharacter, including escaped
@@ -1524,7 +1554,7 @@
 // Advances loc to the first character of 's' following the escaped string.
 std::string parse_substr(string::const_iterator &start,
 			 const string::const_iterator &end,
-			 const char *terminators)
+			 const vector<const char *> &terminators)
 {
   std::string rval="";
   bool done=false;
@@ -1537,7 +1567,7 @@
 	    *start != '!' &&
 	    *start != '~' &&
 	    *start != '|' &&
-	    strchr(terminators, *start) == NULL)
+	    !terminate(start, end, terminators))
 	{
 	  rval += *start;
 	  ++start;
@@ -1569,7 +1599,7 @@
 
 pkg_matcher *parse_atom(string::const_iterator &start,
 			const string::const_iterator &end,
-			const char *terminators,
+			const vector<const char *> &terminators,
 			bool search_descriptions)
 {
   std::string substr;
@@ -1578,7 +1608,7 @@
     ++start;
 
   while(start != end && *start != '|' && *start != ')' &&
-	strchr(terminators, *start) == NULL)
+	!terminate(start, end, terminators))
     {
       if(*start == '!')
 	{
@@ -1591,7 +1621,8 @@
 	// treated normally until the closing paren)
 	{
 	  ++start;
-	  auto_ptr<pkg_matcher> lst(parse_condition_list(start, end, "",
+	  auto_ptr<pkg_matcher> lst(parse_condition_list(start, end,
+							 vector<const char *>(),
 							 search_descriptions));
 
 	  if(!(start != end && *start == ')'))
@@ -1678,7 +1709,7 @@
 		    string::const_iterator nextstart = start;
 
 		    while(nextstart != end && isalpha(*nextstart) &&
-			  strchr(terminators, *nextstart) == NULL)
+			  !terminate(nextstart, end, terminators))
 		      ++nextstart;
 
 		    if(nextstart != end && *nextstart == ':')
@@ -1846,7 +1877,7 @@
 
 pkg_matcher *parse_and_group(string::const_iterator &start,
 			     const string::const_iterator &end,
-			     const char *terminators,
+			     const vector<const char *> &terminators,
 			     bool search_descriptions)
 {
   auto_ptr<pkg_matcher> rval(NULL);
@@ -1854,7 +1885,7 @@
     ++start;
 
   while(start != end && *start != '|' && *start != ')' &&
-	strchr(terminators, *start) == NULL)
+	!terminate(start, end, terminators))
     {
       auto_ptr<pkg_matcher> atom(parse_atom(start, end, terminators,
 					    search_descriptions));
@@ -1865,7 +1896,7 @@
 	rval = auto_ptr<pkg_matcher>(new pkg_and_matcher(rval.release(), atom.release()));
 
       while(start != end && isspace(*start) &&
-	    strchr(terminators, *start) == NULL)
+	    !terminate(start, end, terminators))
 	++start;
     }
 
@@ -1877,16 +1908,16 @@
 
 pkg_matcher *parse_condition_list(string::const_iterator &start,
 				  const string::const_iterator &end,
-				  const char *terminators,
+				  const vector<const char *> &terminators,
 				  bool search_descriptions)
 {
   auto_ptr<pkg_matcher> grp(parse_and_group(start, end, terminators,
 					    search_descriptions));
 
-  while(start != end && isspace(*start) && strchr(terminators, *start) == NULL)
+  while(start != end && isspace(*start) && !terminate(start, end, terminators))
     ++start;
 
-  while(start != end && *start != ')' && strchr(terminators, *start) == NULL)
+  while(start != end && *start != ')' && !terminate(start, end, terminators))
     {
       if(start != end && *start == '|')
 	{
@@ -1911,13 +1942,13 @@
 
 pkg_matcher *parse_pattern(string::const_iterator &start,
 			   const string::const_iterator &end,
-			   const char *terminators,
+			   const std::vector<const char *> &terminators,
 			   bool search_descriptions,
 			   bool flag_errors,
 			   bool require_full_parse)
 {
   // Just filter blank strings out immediately.
-  while(start != end && isspace(*start) && strchr(terminators, *start) == NULL)
+  while(start != end && isspace(*start) && !terminate(start, end, terminators))
     ++start;
 
   if(start == end)

Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.h	Fri Aug  5 02:43:05 2005
@@ -24,6 +24,7 @@
 #define MATCHERS_H
 
 #include <string>
+#include <vector>
 
 #include <apt-pkg/pkgcache.h>
 
@@ -83,13 +84,13 @@
  */
 pkg_matcher *parse_pattern(std::string::const_iterator &start,
 			   const std::string::const_iterator &end,
-			   const char *terminators="",
+			   const std::vector<const char *> &terminators = std::vector<const char *>(),
 			   bool search_descriptions=false,
 			   bool flag_errors=true,
 			   bool require_full_parse=true);
 
 inline pkg_matcher *parse_pattern(const std::string &s,
-				  const char *terminators="",
+				  const std::vector<const char *> &terminators = std::vector<const char *>(),
 				  bool search_descriptions = false,
 				  bool flag_errors = true)
 {



More information about the Aptitude-svn-commit mailing list