]> git.tdb.fi Git - builder.git/commitdiff
Don't apply parts of a pattern that are already present
authorMikko Rasa <tdb@tdb.fi>
Tue, 25 Dec 2018 11:06:30 +0000 (13:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 25 Dec 2018 11:06:30 +0000 (13:06 +0200)
This allows naming a library component "libsomething" without the final
file name having a double lib prefix.

source/pattern.cpp

index 74c7c31cec44f5e3d5f01be9aa5025c1b3a44e6b..51ca9c6f1c94830967ed1f7c2a5a210b9b20c243 100644 (file)
@@ -14,7 +14,12 @@ Pattern::Pattern(const string &pat)
 
 string Pattern::apply(const string &body) const
 {
-       return prefix+body+suffix;
+       string result = body;
+       if(body.compare(0, prefix.size(), prefix))
+               result = prefix+result;
+       if(body.size()>suffix.size() && body.compare(body.size()-suffix.size(), suffix.size(), suffix))
+               result += suffix;
+       return result;
 }
 
 list<string> Pattern::apply_list(const list<Pattern> &patterns, const string &body)