mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Fixed Unexpected Token crashing the process
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
{
|
||||
Reference in New Issue
Block a user