aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Base.cpp7
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/StringUtil.cpp10
-rw-r--r--src/common/io/Stream.cpp13
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() {}