diff --git a/src/error.h b/src/error.h index 71338343..d3358a46 100644 --- a/src/error.h +++ b/src/error.h @@ -44,7 +44,9 @@ struct SourceMetadata { _Str snapshot(int lineno){ _StrStream ss; ss << " " << "File \"" << filename << "\", line " << lineno << '\n'; - ss << " " << getLine(lineno) << '\n'; + _Str line = getLine(lineno).__lstrip(); + if(line.empty()) line = ""; + ss << " " << line << '\n'; return ss.str(); } }; diff --git a/src/str.h b/src/str.h index 64818473..ab3cdfaa 100644 --- a/src/str.h +++ b/src/str.h @@ -121,6 +121,14 @@ public: operator const char*() const { return _s.c_str(); } + + _Str __lstrip() const { + std::string copy(_s); + copy.erase(copy.begin(), std::find_if(copy.begin(), copy.end(), [](char c) { + return !std::isspace(c); + })); + return _Str(copy); + } };