From 402a19ee62dc2d3465b48fc518bdae265fc3e090 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 23 Jul 2012 13:23:08 +0300 Subject: [PATCH] Add helper function to apply a list of patterns --- source/pattern.cpp | 8 ++++++++ source/pattern.h | 4 ++++ source/virtualfilesystem.cpp | 12 ++---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/source/pattern.cpp b/source/pattern.cpp index e87981f..74c7c31 100644 --- a/source/pattern.cpp +++ b/source/pattern.cpp @@ -16,3 +16,11 @@ string Pattern::apply(const string &body) const { return prefix+body+suffix; } + +list Pattern::apply_list(const list &patterns, const string &body) +{ + list result; + for(list::const_iterator i=patterns.begin(); i!=patterns.end(); ++i) + result.push_back(i->apply(body)); + return result; +} diff --git a/source/pattern.h b/source/pattern.h index 4c79b4b..5965efa 100644 --- a/source/pattern.h +++ b/source/pattern.h @@ -1,6 +1,7 @@ #ifndef PATTERN_H_ #define PATTERN_H_ +#include #include /** @@ -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 apply_list(const std::list &, const std::string &); }; #endif diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 60867cf..c012301 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -78,19 +78,11 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath list shared_names; if(mode!=BuildInfo::FORCE_STATIC) - { - const list &shared_patterns = arch.get_shared_library_patterns(); - for(list::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 static_names; if(mode!=BuildInfo::FORCE_DYNAMIC) - { - const list &static_patterns = arch.get_static_library_patterns(); - for(list::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::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i) { -- 2.45.2