diff options
Diffstat (limited to 'source/10-common/Utils.hpp')
-rw-r--r-- | source/10-common/Utils.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/source/10-common/Utils.hpp b/source/10-common/Utils.hpp index 9560b57..fdf0f5d 100644 --- a/source/10-common/Utils.hpp +++ b/source/10-common/Utils.hpp @@ -19,8 +19,21 @@ enum IoMode { FILE* OpenCstdioFile(const std::filesystem::path& path, IoMode mode, bool binary = false); FILE* OpenCstdioFile(const char* path, IoMode mode, bool binary = false); +/// Retrieve a whole line (marked by `\n` or EOF) into the buffer. If the line ends with EOF, two things happen: +/// 1. a `\n` character is appended to the line content, emulating as-if the line ended with `\n`. +/// 2. `false` is returned +/// Otherwise, `true` is returned. +/// +/// Empty lines are not skipped at all, including the very last empty line if it exists. +bool ReadCstdioLine(FILE* file, std::string& buffer); +/// Same as the other overload, except working with a fixed-size buffer. +/// NOTE: this also gives the length of the line compared to `std::fgets`. +/// `std::fgets` requires us to run `std::strlen` on the output again to find the length +bool ReadCstdioLine(FILE* file, char* buffer, size_t bufferSize, size_t* outLineLength = nullptr); + std::string ReadFileAsString(const std::filesystem::path& path); + constexpr float Abs(float v) noexcept { return v < 0.0f ? -v : v; } |