diff --git a/src/headers/arguments.hpp b/src/headers/arguments.hpp index 8b5db4b..52627c3 100644 --- a/src/headers/arguments.hpp +++ b/src/headers/arguments.hpp @@ -29,7 +29,7 @@ public: unsigned long definePos = str.find_last_of('=') + 1; return str.size() > definePos ? str.substr(definePos) : string(); } - ArgumentAssignable(string name, const span& possibleValues) : Argument(move(name)), values() { + ArgumentAssignable(string name, const span& possibleValues): Argument(move(name)), values() { values.reserve(possibleValues.size()); move(possibleValues.begin(), possibleValues.end(), back_inserter(values)); } diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 7481e7d..c39baa1 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -12,17 +12,20 @@ #define INCLUDECOMPONENT(X) virtual void on(const X& parseComponent) {} class Target { + constexpr static const char* const interpolationString = "${"; + constexpr static const char* const interpolationCloseString = "}"; protected: std::stringstream output; INCLUDECOMPONENT(StandardComponents::Define); INCLUDECOMPONENT(StandardComponents::types::String); void stringInterpolation(string view, const char* openMultiline = "", const char* closeMultiline = "", const char* concatenationCharacters = "+") { vector interpolationVector; - const string interpolationString = "${"; - unsigned long occurence_position = view.find(interpolationString); - while (occurence_position != string::npos) { - interpolationVector.push_back(occurence_position); - occurence_position = view.find(interpolationString, occurence_position + interpolationString.size()); + unsigned long occurrence_position = view.find(interpolationString); + if (view.find(interpolationCloseString) != string::npos) { + while (occurrence_position != string::npos) { + interpolationVector.push_back(occurrence_position); + occurrence_position = view.find(interpolationString, occurrence_position + strlen(interpolationString)); + } } unsigned long newLine = view.find('\n'); const bool multiline = newLine != string::npos && not !strcmp(openMultiline, "") && not !strcmp(closeMultiline, openMultiline); @@ -38,21 +41,21 @@ protected: if (not interpolationVector.empty()) { unsigned long closingBrace = 0; for (unsigned long i = 0; i < interpolationVector.size(); ++i) { - const auto& occurence = interpolationVector[i]; + const auto& occurrence = interpolationVector[i]; const bool hasNext = (i + 1) < interpolationVector.size(); - const bool oldClosingBraceIsFar = closingBrace >= occurence; + const bool oldClosingBraceIsFar = closingBrace >= occurrence; if (i > 0) output << concatenationCharacters; - output << openCharacters << view.substr(closingBrace + (i > 0), (occurence - closingBrace) - (i > 0)); - closingBrace = view.find_first_of('}', occurence); + output << openCharacters << view.substr(closingBrace + (i > 0), (occurrence - closingBrace) - (i > 0)); + closingBrace = view.find_first_of(interpolationCloseString, occurrence); const bool closingBraceIsNPOS = closingBrace == string::npos; const bool wrongClosingBrace = !closingBraceIsNPOS && ((hasNext && closingBrace > interpolationVector[i + 1])); if (closingBraceIsNPOS || wrongClosingBrace) { - output << view.substr(occurence, (hasNext ? interpolationVector[i + 1] - occurence : 0)); + output << view.substr(occurrence, (hasNext ? interpolationVector[i + 1] - occurrence : 0)); } output << closeCharacters; if (not closingBraceIsNPOS && not wrongClosingBrace) { output << concatenationCharacters; - output << view.substr(occurence + interpolationString.size(), (closingBrace - occurence) - interpolationString.size()); + output << view.substr(occurrence + strlen(interpolationString), (closingBrace - occurrence) - strlen(interpolationString)); } } } else output << openCharacters << view << closeCharacters << '\n';