diff options
author | crupest <crupest@outlook.com> | 2022-01-17 20:49:37 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-17 20:49:37 +0800 |
commit | 87658408858dfad8c1fc85b048d46b9a6345580d (patch) | |
tree | 03484fb8e64b31fe6e1f146771c423914b922e99 /src | |
parent | 0dd9ded17f0b8461d54ccfbc66886395fab0aa98 (diff) | |
download | cru-87658408858dfad8c1fc85b048d46b9a6345580d.tar.gz cru-87658408858dfad8c1fc85b048d46b9a6345580d.tar.bz2 cru-87658408858dfad8c1fc85b048d46b9a6345580d.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Base.cpp | 7 | ||||
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/StringUtil.cpp | 10 | ||||
-rw-r--r-- | src/common/io/Stream.cpp | 13 |
4 files changed, 30 insertions, 1 deletions
diff --git a/src/common/Base.cpp b/src/common/Base.cpp new file mode 100644 index 00000000..dbbc0d61 --- /dev/null +++ b/src/common/Base.cpp @@ -0,0 +1,7 @@ +#include "cru/common/Base.hpp" + +#include <stdexcept> + +namespace cru { +void UnreachableCode() { std::terminate(); } +} // namespace cru diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index b5b20d46..d1e3e35a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,5 +1,6 @@ set(CRU_BASE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/common) add_library(cru_base SHARED + Base.cpp Exception.cpp Logger.cpp PropertyTree.cpp diff --git a/src/common/StringUtil.cpp b/src/common/StringUtil.cpp index 6e478033..04435a0a 100644 --- a/src/common/StringUtil.cpp +++ b/src/common/StringUtil.cpp @@ -1,5 +1,4 @@ #include "cru/common/StringUtil.hpp" -#include <functional> #include "cru/common/Base.hpp" #include "cru/common/Exception.hpp" @@ -258,4 +257,13 @@ char16_t ToUpper(char16_t c) { bool IsWhitespace(char16_t c) { return c == u' ' || c == u'\t' || c == u'\n' || c == u'\r'; } + +Utf8CodePointIterator CreateUtf8Iterator(const std::byte* buffer, Index size) { + return Utf8CodePointIterator(reinterpret_cast<const char*>(buffer), size); +} + +Utf8CodePointIterator CreateUtf8Iterator(const std::vector<std::byte>& buffer) { + return CreateUtf8Iterator(buffer.data(), buffer.size()); +} + } // namespace cru diff --git a/src/common/io/Stream.cpp b/src/common/io/Stream.cpp index 5062aa72..bf102441 100644 --- a/src/common/io/Stream.cpp +++ b/src/common/io/Stream.cpp @@ -27,6 +27,19 @@ Index Stream::Write(const char* buffer, Index size) { return Write(reinterpret_cast<const std::byte*>(buffer), size); } +std::vector<std::byte> Stream::ReadAll() { + std::vector<std::byte> buffer; + buffer.resize(GetSize()); + Read(buffer.data(), 0, buffer.size()); + return buffer; +} + +String Stream::ReadAllAsString() { + auto buffer = ReadAll(); + return String::FromUtf8(reinterpret_cast<const char*>(buffer.data()), + buffer.size()); +} + void Stream::Flush() {} void Stream::Close() {} |