summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-03-06 21:22:05 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-03-07 20:17:35 +0100
commit62858602c6aaa8c6c28bf82aa4e1244c1214b869 (patch)
tree991e7306448957caf5bec44362ee9a835820f499 /src
parent38ab9d38b52c873da1338f4d5eb58edb2ad5c2bc (diff)
downloadccache-62858602c6aaa8c6c28bf82aa4e1244c1214b869.tar.gz
enhance: Add util::read_file_part<std::string> implementation
Diffstat (limited to 'src')
-rw-r--r--src/util/file.cpp5
-rw-r--r--src/util/file.hpp7
2 files changed, 8 insertions, 4 deletions
diff --git a/src/util/file.cpp b/src/util/file.cpp
index 7b718969..d084f88c 100644
--- a/src/util/file.cpp
+++ b/src/util/file.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
@@ -255,6 +255,9 @@ read_file_part(const std::string& path, size_t pos, size_t count)
template nonstd::expected<util::Bytes, std::string>
read_file_part(const std::string& path, size_t pos, size_t count);
+template nonstd::expected<std::string, std::string>
+read_file_part(const std::string& path, size_t pos, size_t count);
+
template nonstd::expected<std::vector<uint8_t>, std::string>
read_file_part(const std::string& path, size_t pos, size_t count);
diff --git a/src/util/file.hpp b/src/util/file.hpp
index c74b58dc..0ae0a57f 100644
--- a/src/util/file.hpp
+++ b/src/util/file.hpp
@@ -61,9 +61,10 @@ nonstd::expected<T, std::string> read_file(const std::string& path,
// Return (at most) `count` bytes from `path` starting at position `pos`.
//
-// `T` should be `util::Bytes` or `std::vector<uint8_t>`. If `T` is
-// `std::string` and the content starts with a UTF-16 little-endian BOM on
-// Windows then it will be converted to UTF-8.
+// `T` should be `util::Bytes` or `std::vector<uint8_t>` for binary data and
+// `std::string` for text data. If `T` is `std::string` and the content starts
+// with a UTF-16 little-endian BOM on Windows then it will be converted to
+// UTF-8.
template<typename T>
nonstd::expected<T, std::string>
read_file_part(const std::string& path, size_t pos, size_t count);