aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-04-01 16:08:12 +0800
committercrupest <crupest@outlook.com>2019-04-01 16:08:12 +0800
commit055a3cde0cd19c896f3e498b774078654555c065 (patch)
treebadbd1350daea36b87e98ada60f55ef5a2168bc9 /src
parent0a429ee13c9fb9a9da6df62b1ebae101180278f5 (diff)
downloadcru-055a3cde0cd19c896f3e498b774078654555c065.tar.gz
cru-055a3cde0cd19c896f3e498b774078654555c065.tar.bz2
cru-055a3cde0cd19c896f3e498b774078654555c065.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/platform_win/CMakeLists.txt1
-rw-r--r--src/platform_win/string_util.cpp (renamed from src/util/string_util.cpp)20
-rw-r--r--src/util/string_util.hpp8
4 files changed, 11 insertions, 21 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 75e6a0c2..8041d8cc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,8 +13,7 @@ add_library(cru_ui STATIC
ui/render/flex_layout_render_object.cpp
ui/render/render_object.cpp
ui/render/text_render_object.cpp
- ui/render/window_render_object.cpp
- util/string_util.cpp)
+ ui/render/window_render_object.cpp)
target_include_directories(cru_ui PUBLIC ${PROJECT_SOURCE_DIR}/include .)
diff --git a/src/platform_win/CMakeLists.txt b/src/platform_win/CMakeLists.txt
index c8a5840e..8edf646e 100644
--- a/src/platform_win/CMakeLists.txt
+++ b/src/platform_win/CMakeLists.txt
@@ -3,6 +3,7 @@ add_library(cru_platform_win STATIC
exception.cpp
god_window.cpp
graph_manager.cpp
+ string_util.cpp
timer.cpp
win_application.cpp
win_brush.cpp
diff --git a/src/util/string_util.cpp b/src/platform_win/string_util.cpp
index c9391fc6..21d82c81 100644
--- a/src/util/string_util.cpp
+++ b/src/platform_win/string_util.cpp
@@ -1,21 +1,19 @@
-#include "string_util.hpp"
+#include "cru/platform/string_util.hpp"
-#include <Windows.h>
+#include "cru/platform/win/exception.hpp"
-#include "exception.hpp"
-
-namespace cru::util {
-MultiByteString ToUtf8String(const StringView& string) {
- if (string.empty()) return MultiByteString();
+namespace cru::platform::util {
+std::string ToUtf8String(const std::wstring_view& string) {
+ if (string.empty()) return std::string();
const auto length = ::WideCharToMultiByte(CP_UTF8, 0, string.data(), -1,
nullptr, 0, nullptr, nullptr);
- MultiByteString result;
- result.reserve(length);
+ std::string result;
+ result.resize(length);
if (::WideCharToMultiByte(CP_UTF8, 0, string.data(), -1, result.data(),
- static_cast<int>(result.capacity()), nullptr,
+ static_cast<int>(result.size()), nullptr,
nullptr) == 0)
- throw Win32Error(::GetLastError(),
+ throw win::Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-8.");
return result;
}
diff --git a/src/util/string_util.hpp b/src/util/string_util.hpp
deleted file mode 100644
index 6d060089..00000000
--- a/src/util/string_util.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-#include "pre.hpp"
-
-#include "base.hpp"
-
-namespace cru::util {
-MultiByteString ToUtf8String(const StringView& string);
-}