diff --git a/ZSharp/builtin.h b/ZSharp/builtin.h index 97793b1..d27fd36 100644 --- a/ZSharp/builtin.h +++ b/ZSharp/builtin.h @@ -146,7 +146,7 @@ void PrintColored(std::string text, std::string fgColor, std::string bgColor, bo int LogWarning(const string& warningText) { PrintColored("WARNING: ", yellowFGColor, "", true); - PrintColored(warningText, yellowFGColor, "", true); + PrintColored(escaped(warningText), yellowFGColor, "", true); cerr << std::endl; //cout << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl; return 1; @@ -184,7 +184,7 @@ int InterpreterLog(const string& logText) PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true); PrintColored("ZSharp: ", yellowFGColor, "", true); - PrintColored(logText, greenFGColor, "", true); + PrintColored(escaped(logText), greenFGColor, "", true); cout << std::endl; //cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mZSharp: \x1B[32m" << logText << "\033[0m\t\t" << endl; return 1; @@ -221,7 +221,7 @@ int LogCriticalError(const string& errorText) PrintColored("[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] ", blueFGColor, "", true); PrintColored("ZSharp: ", yellowFGColor, "", true); - PrintColored(errorText, redFGColor, "", true); + PrintColored(escaped(errorText), redFGColor, "", true); cerr << std::endl; InterpreterLog("Press Enter to Exit..."); cin.ignore(); diff --git a/ZSharp/strops.cpp b/ZSharp/strops.cpp index dc2a18e..5cfe884 100644 --- a/ZSharp/strops.cpp +++ b/ZSharp/strops.cpp @@ -51,6 +51,26 @@ string unescape(const string& s) return res; } +std::string escaped(const std::string& input) +{ + std::string output; + output.reserve(input.size()); + for (const char c : input) { + switch (c) { + case '\a': output += "\\a"; break; + case '\b': output += "\\b"; break; + case '\f': output += "\\f"; break; + case '\n': output += "\\n"; break; + case '\r': output += "\\r"; break; + case '\t': output += "\\t"; break; + case '\v': output += "\\v"; break; + default: output += c; break; + } + } + + return output; +} + string StringRaw(const string& s) { string str = trim(s); diff --git a/ZSharp/strops.h b/ZSharp/strops.h index 24a171d..31ae45e 100644 --- a/ZSharp/strops.h +++ b/ZSharp/strops.h @@ -69,4 +69,6 @@ bool isEscaped(const string& str, int curChar); bool startsWith(const string& str, const string& lookFor); +std::string escaped(const std::string& input); + #endif