libcppwrap
A collection of C++ wrappers for native APIs
Loading...
Searching...
No Matches
slurp.hpp
Go to the documentation of this file.
1//
2// libcppwrap - A collection of C++ wrappers for native APIs
3// Copyright (C) 2021-2023 David A. Norris <danorris@gmail.com>
4// Published under the MIT license - https://opensource.org/licenses/MIT
5//
6
7#pragma once
8
9#include <filesystem>
10#include <string>
11#include <string_view>
12
13namespace wx
14{
29 std::string read_file_as_string(const char *path);
30
35
45 std::string slurp(const char *path);
46
50 inline std::string slurp(const std::string& path) { return slurp(path.c_str()); }
51
55 inline std::string slurp(const std::filesystem::path& path) { return slurp(path.c_str()); }
56
64 void spew(const char *path, std::string_view str);
65
69 inline void spew(const std::string& path, std::string_view str) { return spew(path.c_str(), str); }
70
74 inline void spew(const std::filesystem::path& path, std::string_view str) { return spew(path.c_str(), str); }
75}
T c_str(T... args)
Definition: ipv6.hpp:14
std::string read_file_as_string(const char *path)
Reads the contents of a file as a string.
Definition: slurp.cpp:19
std::string slurp(const char *path)
Reads the contents of a file as a string with trailing whitespace removed.
Definition: slurp.cpp:51
void spew(const char *path, std::string_view str)
Writes a string to a file.
Definition: slurp.cpp:58