]> git.tdb.fi Git - builder.git/blobdiff - source/architecture.cpp
Introduce a helper function in Architecture to pick the best matching name
[builder.git] / source / architecture.cpp
index a9434986a91170a3de3ef4c7e6462b7b2ee1c911..ac31abdc30428307fd46278a44508b1222872dfb 100644 (file)
@@ -154,6 +154,30 @@ bool Architecture::match_name(const string &pattern) const
        return !negate;
 }
 
+string Architecture::best_match(const list<string> &names) const
+{
+       string best;
+       unsigned best_size = 0;
+       for(list<string>::const_iterator i=names.begin(); i!=names.end(); ++i)
+               if(match_name(*i))
+               {
+                       /* TODO Do full parse and alias resolution here?  Otherwise x86 and
+                       x86_64 are treated as equally good, even though the latter is more
+                       specific. */
+                       unsigned size = 1;
+                       for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+                               size += (*j=='-');
+
+                       if(size>best_size)
+                       {
+                               best = *i;
+                               best_size = size;
+                       }
+               }
+
+       return best;
+}
+
 void Architecture::resolve_aliases(vector<string> &parts)
 {
        for(unsigned i=0; i<parts.size(); ++i)