aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2022-06-11 23:22:00 +0200
committerStefan Boberg <[email protected]>2022-06-11 23:22:00 +0200
commit348ae50c946b541ce935703045ab98a49d809ed4 (patch)
treea400285c9e5ae215dc7ef3b2958ce922f48ec7bc /zencore
parentfixed mac build ("unused" variable) (diff)
parentclang-format fix (diff)
downloadzen-348ae50c946b541ce935703045ab98a49d809ed4.tar.xz
zen-348ae50c946b541ce935703045ab98a49d809ed4.zip
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zencore')
-rw-r--r--zencore/filesystem.cpp20
-rw-r--r--zencore/include/zencore/filesystem.h1
-rw-r--r--zencore/include/zencore/iobuffer.h6
-rw-r--r--zencore/include/zencore/string.h2
4 files changed, 28 insertions, 1 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index bd85f5a11..01997daae 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -6,6 +6,7 @@
#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
#include <zencore/logging.h>
+#include <zencore/stream.h>
#include <zencore/string.h>
#include <zencore/testing.h>
@@ -637,6 +638,25 @@ FileContents::Flatten()
}
FileContents
+ReadStdIn()
+{
+ BinaryWriter Writer;
+
+ do
+ {
+ uint8_t ReadBuffer[1024];
+
+ size_t BytesRead = fread(ReadBuffer, 1, sizeof ReadBuffer, stdin);
+ Writer.Write(ReadBuffer, BytesRead);
+ } while (!feof(stdin));
+
+ FileContents Contents;
+ Contents.Data.emplace_back(IoBuffer(IoBuffer::Clone, Writer.GetData(), Writer.GetSize()));
+
+ return Contents;
+}
+
+FileContents
ReadFile(std::filesystem::path Path)
{
uint64_t FileSizeBytes;
diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h
index 6d07a79b4..f49135687 100644
--- a/zencore/include/zencore/filesystem.h
+++ b/zencore/include/zencore/filesystem.h
@@ -46,6 +46,7 @@ struct FileContents
IoBuffer Flatten();
};
+ZENCORE_API FileContents ReadStdIn();
ZENCORE_API FileContents ReadFile(std::filesystem::path Path);
ZENCORE_API bool ScanFile(std::filesystem::path Path, uint64_t ChunkSize, std::function<void(const void* Data, size_t Size)>&& ProcessFunc);
ZENCORE_API void WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t BufferCount);
diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h
index bf658922d..b38201ba3 100644
--- a/zencore/include/zencore/iobuffer.h
+++ b/zencore/include/zencore/iobuffer.h
@@ -390,6 +390,12 @@ public:
return reinterpret_cast<const T*>(m_Core->DataPointer());
}
+ template<typename T>
+ [[nodiscard]] T* MutableData() const
+ {
+ return reinterpret_cast<T*>(m_Core->MutableDataPointer());
+ }
+
private:
RefPtr<IoBufferCore> m_Core = new IoBufferCore;
diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h
index 92f567dae..7ea8c029f 100644
--- a/zencore/include/zencore/string.h
+++ b/zencore/include/zencore/string.h
@@ -933,7 +933,7 @@ public:
return *Skip(Str, Set) == '\0';
}
- ////////// Algorithms for string types like FStringView and FString //////////
+ ////////// Algorithms for string types like std::string_view and std::string //////////
/** Get initial substring with all characters in set */
template<class StringType>