diff --git a/include/blt/std/loader.h b/include/blt/std/loader.h index f2e8643..f5cc840 100755 --- a/include/blt/std/loader.h +++ b/include/blt/std/loader.h @@ -24,9 +24,9 @@ namespace blt::fs char close = '>'; }; - std::string getFile(const std::string& path); + std::string getFile(std::string_view path); - std::vector getLinesFromFile(const std::string& path); + std::vector getLinesFromFile(std::string_view path); /** * Recursively include files @@ -35,7 +35,7 @@ namespace blt::fs * @param guards characters used to identify the parts that specify the file path. if empty it will assume everything after the include header * @return a list of lines in all files. added together in order. */ - std::vector recursiveInclude(const std::string& path, const std::string& include_header = "#include", + std::vector recursiveInclude(std::string_view path, const std::string& include_header = "#include", const std::vector& guards = {{'<', '>'}, {'"', '"'}}); static inline std::string loadBrainFuckFile(const std::string& path) @@ -53,7 +53,7 @@ namespace blt::fs return buffer; } - static inline std::string loadShaderFile(const std::string& path) + static inline std::string loadShaderFile(std::string_view path) { std::stringstream stringStream; diff --git a/src/blt/std/loader.cpp b/src/blt/std/loader.cpp index 9efba5c..b13c11f 100755 --- a/src/blt/std/loader.cpp +++ b/src/blt/std/loader.cpp @@ -6,18 +6,18 @@ #include #include -std::vector blt::fs::getLinesFromFile(const std::string& path) +std::vector blt::fs::getLinesFromFile(std::string_view path) { std::string file = getFile(path); + // we only use unix line endings here... + string::replaceAll(file, "\r", ""); // split the file into the lines, this way we can get out the #include statements. return string::split(file, "\n"); } -std::vector blt::fs::recursiveInclude(const std::string& path, const std::string& include_header, +std::vector blt::fs::recursiveInclude(std::string_view path, const std::string& include_header, const std::vector& guards) { - std::string pathOnly = path.substr(0, path.find_last_of('/')); - auto mainLines = getLinesFromFile(path); std::vector return_lines; @@ -61,7 +61,7 @@ std::vector blt::fs::recursiveInclude(const std::string& path, cons return return_lines; } -std::string blt::fs::getFile(const std::string& path) +std::string blt::fs::getFile(std::string_view path) { std::string file_contents; std::ifstream the_file; @@ -72,7 +72,7 @@ std::string blt::fs::getFile(const std::string& path) try { // open file - the_file.open(path); + the_file.open(std::string(path)); std::stringstream file_stream; // read file's buffer contents into streams file_stream << the_file.rdbuf(); @@ -82,7 +82,7 @@ std::string blt::fs::getFile(const std::string& path) file_contents = file_stream.str(); } catch (std::ifstream::failure& e) { - BLT_WARN("Unable to read file '%s'!\n", path.c_str()); + BLT_WARN("Unable to read file '%s'!\n", std::string(path).c_str()); BLT_WARN("Exception: %s", e.what()); throw std::runtime_error("Failed to read file!\n"); }