From d2e7188e33a58cab05ef6292795303ad4b92a5f7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 7 Dec 2024 17:14:45 +0100 Subject: WIP --- src/util.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index 73b158d..d1f20d8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -7,10 +7,17 @@ #include #include +namespace { +char to_lower_c(char ch) +{ + return static_cast(::tolower(ch)); +} +} + std::string to_lower(const std::string& str) { std::string out{str}; - std::transform(out.begin(), out.end(), out.begin(), ::tolower); + std::transform(out.begin(), out.end(), out.begin(), to_lower_c); return out; } @@ -19,17 +26,23 @@ std::string readFile(const std::string& fileName) std::ifstream ifs(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - std::ifstream::pos_type fileSize = ifs.tellg(); + auto tell = ifs.tellg(); + if(tell < 0) + { + return {}; + } + auto fileSize = static_cast(tell); ifs.seekg(0, std::ios::beg); - std::vector bytes(static_cast(fileSize)); - ifs.read(bytes.data(), fileSize); + std::vector bytes(fileSize); + ifs.read(bytes.data(), static_cast(bytes.size())); - return {bytes.data(), static_cast(fileSize)}; + return { bytes.data(), bytes.size() }; } std::vector readDeps(const std::string& depFile) { + return {};// TODO: parse json if(!std::filesystem::exists(depFile)) { return {}; -- cgit v1.2.3