]> git.tdb.fi Git - builder.git/commitdiff
Add helper function to apply a list of patterns
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Jul 2012 10:23:08 +0000 (13:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Jul 2012 10:23:08 +0000 (13:23 +0300)
source/pattern.cpp
source/pattern.h
source/virtualfilesystem.cpp

index e87981f8f941603653de1bbf9f5e33ba068bcc45..74c7c31cec44f5e3d5f01be9aa5025c1b3a44e6b 100644 (file)
@@ -16,3 +16,11 @@ string Pattern::apply(const string &body) const
 {
        return prefix+body+suffix;
 }
+
+list<string> Pattern::apply_list(const list<Pattern> &patterns, const string &body)
+{
+       list<string> result;
+       for(list<Pattern>::const_iterator i=patterns.begin(); i!=patterns.end(); ++i)
+               result.push_back(i->apply(body));
+       return result;
+}
index 4c79b4b83b732656d96d8866bb4f3cf9f45318f9..5965efaed69886ea489679f93b0e0d13774eef4d 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef PATTERN_H_
 #define PATTERN_H_
 
+#include <list>
 #include <string>
 
 /**
@@ -21,6 +22,9 @@ public:
 
        /** Applies the pattern to a body string. */
        std::string apply(const std::string &) const;
+
+       /** Applies a list of patterns to the same body. */
+       static std::list<std::string> apply_list(const std::list<Pattern> &, const std::string &);
 };
 
 #endif
index 60867cf7a4feb3dda5638ee35c9b7a2a956e6d88..c0123015fcd0d78c0d1bc77e772d74fbfcb01a1e 100644 (file)
@@ -78,19 +78,11 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath
 
        list<string> shared_names;
        if(mode!=BuildInfo::FORCE_STATIC)
-       {
-               const list<Pattern> &shared_patterns = arch.get_shared_library_patterns();
-               for(list<Pattern>::const_iterator i=shared_patterns.begin(); i!=shared_patterns.end(); ++i)
-                       shared_names.push_back(i->apply(lib));
-       }
+               shared_names = Pattern::apply_list(arch.get_shared_library_patterns(), lib);
 
        list<string> static_names;
        if(mode!=BuildInfo::FORCE_DYNAMIC)
-       {
-               const list<Pattern> &static_patterns = arch.get_static_library_patterns();
-               for(list<Pattern>::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i)
-                       static_names.push_back(i->apply(lib));
-       }
+               static_names = Pattern::apply_list(arch.get_static_library_patterns(), lib);
 
        for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
        {