From daac042aa64e944248160c1b38b9a31e3972bb50 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 25 Dec 2018 13:06:30 +0200 Subject: [PATCH] Don't apply parts of a pattern that are already present This allows naming a library component "libsomething" without the final file name having a double lib prefix. --- source/pattern.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/pattern.cpp b/source/pattern.cpp index 74c7c31..51ca9c6 100644 --- a/source/pattern.cpp +++ b/source/pattern.cpp @@ -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 Pattern::apply_list(const list &patterns, const string &body) -- 2.45.2