Fixed Unexpected Token crashing the process

This commit is contained in:
Pasha Bibko
2025-05-07 16:53:10 +01:00
parent 4e78a9f6ae
commit 6783564f10
10 changed files with 53 additions and 51 deletions

View File

@@ -151,14 +151,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="inc\Console.h" />
<ClInclude Include="inc\IO.h" />
<ClInclude Include="inc\Error.h" />
<ClInclude Include="inc\Logger.h" />
<ClInclude Include="inc\ThrowIf.h" />
<ClInclude Include="LX-Common.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Console.cpp" />
<ClCompile Include="src\IO.cpp" />
<ClCompile Include="src\Error.cpp" />
<ClCompile Include="src\Logger.cpp" />
<ClCompile Include="src\pch.cpp">

View File

@@ -14,7 +14,7 @@
<ClInclude Include="LX-Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\Console.h">
<ClInclude Include="inc\IO.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="inc\Error.h">
@@ -34,7 +34,7 @@
<ClCompile Include="src\Logger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Console.cpp">
<ClCompile Include="src\IO.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Error.cpp">

View File

@@ -65,7 +65,7 @@
// Includes the rest of common //
#include <inc/Console.h>
#include <inc/Error.h>
#include <inc/Logger.h>
#include <inc/ThrowIf.h>
#include <inc/IO.h>

View File

@@ -23,6 +23,25 @@ namespace LX
// Prints a string to std::cout with a certain color using Win32 API //
extern "C" void COMMON_API PrintStringAsColor(const std::string& str, Color c);
inline std::string ReadFileToString(const std::filesystem::path& path, const std::string errorName = "input file path")
{
// Verifies the file path is valid //
ThrowIf<LX::InvalidFilePath>(std::filesystem::exists(path) == false, errorName, path);
// Opens the file //
std::ifstream file(path, std::ios::binary | std::ios::ate); // Opens in binary and at the end (microptimsation)
ThrowIf<LX::InvalidFilePath>(file.is_open() == false, errorName, path);
// Stores the length of the string and goes back to the beginning //
const std::streamsize len = file.tellg(); // tellg returns length because it was opened at the end
file.seekg(0, std::ios::beg);
// Transfers the file contents to the output //
std::string contents(len, '\0'); // Allocates an empty string which is the size of the file
file.read(&contents[0], len);
return contents;
}
// Util function for getting a line of the source at a given index (used for errors) //
inline std::string GetLineAtIndexOf(const std::string& src, const std::streamsize index) // <- Has to be inline because of C++ types
{