AoC code coverage
Current view: top level - aoclib - StringUtils.cpp (source / functions) Coverage Total Hit
Test: master Lines: 100.0 % 13 13
Test Date: 2026-05-24 23:46:10 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #include "StringUtils.h"
       2              : #include "IntegerCast.h"
       3              : 
       4              : #include <libassert/assert.hpp>
       5              : 
       6              : #include <fstream>
       7              : 
       8        36738 : std::string readFileAsString(std::filesystem::path const &path) {
       9        36738 :   ASSERT(exists(path), "File not found!", path.string());
      10        36738 :   std::string result;
      11        36738 :   std::ifstream ifs(path);
      12        36738 :   ifs.seekg(0, std::ios::end);
      13        36738 :   std::size_t size = ifs.tellg();
      14        36738 :   ifs.seekg(0);
      15        36738 :   result.resize_and_overwrite(size, [&ifs](char *buffer, std::size_t size) {
      16        36738 :     ifs.read(buffer, integerCast<std::streamsize>(size));
      17        36738 :     return integerCast<std::size_t>(ifs.gcount());
      18        36738 :   });
      19        36738 :   return result;
      20        36738 : }
        

Generated by: LCOV version 2.4-0