blueloveTH 3 anni fa
parent
commit
4c27b5210b
2 ha cambiato i file con 11 aggiunte e 1 eliminazioni
  1. 3 1
      src/error.h
  2. 8 0
      src/str.h

+ 3 - 1
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();
     }
 };

+ 8 - 0
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);
+    }
 };