diff options
Diffstat (limited to 'src')
60 files changed, 209 insertions, 259 deletions
diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp index a1c19e08..1410ff7c 100644 --- a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp +++ b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp @@ -107,7 +107,7 @@ void StyleRuleSetEditor::UpdateView( break; } case ui::model::ListChangeType::kItemMove: { - throw Exception(u"Not supported now!"); + throw Exception("Not supported now!"); break; } case ui::model::ListChangeType::kClear: { diff --git a/src/ThemeBuilder/components/conditions/ConditionEditor.cpp b/src/ThemeBuilder/components/conditions/ConditionEditor.cpp index 421bb028..3435b36f 100644 --- a/src/ThemeBuilder/components/conditions/ConditionEditor.cpp +++ b/src/ThemeBuilder/components/conditions/ConditionEditor.cpp @@ -44,7 +44,7 @@ std::unique_ptr<ConditionEditor> CreateConditionEditor( result->SetValue(checked_condition); return result; } else { - throw Exception(u"Unknown condition type"); + throw Exception("Unknown condition type"); } } } // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/stylers/StylerEditor.cpp b/src/ThemeBuilder/components/stylers/StylerEditor.cpp index b3147a15..4fd52b96 100644 --- a/src/ThemeBuilder/components/stylers/StylerEditor.cpp +++ b/src/ThemeBuilder/components/stylers/StylerEditor.cpp @@ -58,7 +58,7 @@ std::unique_ptr<StylerEditor> CreateStylerEditor(ui::style::Styler* styler) { editor->SetValue(font_styler); return editor; } else { - throw Exception(u"Unknown styler type"); + throw Exception("Unknown styler type"); } } } // namespace cru::theme_builder::components::stylers diff --git a/src/base/Buffer.cpp b/src/base/Buffer.cpp index 1213364a..386e46cc 100644 --- a/src/base/Buffer.cpp +++ b/src/base/Buffer.cpp @@ -7,7 +7,7 @@ namespace cru { namespace { void CheckSize(Index size) { if (size < 0) { - throw Exception(u"Size of buffer can't be smaller than 0."); + throw Exception("Size of buffer can't be smaller than 0."); } } } // namespace @@ -144,7 +144,7 @@ Index Buffer::PushBack(const std::byte* other, Index other_size, void Buffer::PushBackCount(Index count) { if (count < 0 || count > GetBackFree()) { - throw Exception(u"Count out of range in PushBackCount."); + throw Exception("Count out of range in PushBackCount."); } used_end_ += count; } diff --git a/src/base/Exception.cpp b/src/base/Exception.cpp index 1f03c2ba..5bfe27db 100644 --- a/src/base/Exception.cpp +++ b/src/base/Exception.cpp @@ -10,9 +10,6 @@ namespace cru { Exception::Exception(std::string message, std::shared_ptr<std::exception> inner) : message_(std::move(message)), inner_(std::move(inner)) {} -Exception::Exception(StringView message, std::shared_ptr<std::exception> inner) - : message_(message.ToUtf8()), inner_(std::move(inner)) {} - Exception::~Exception() {} const char* Exception::what() const noexcept { return message_.c_str(); } @@ -31,16 +28,6 @@ void Exception::AppendMessage( if (additional_message) AppendMessage(*additional_message); } -void Exception::SetMessage(StringView message) { SetMessage(message.ToUtf8()); } - -void Exception::AppendMessage(StringView additional_message) { - AppendMessage(additional_message.ToUtf8()); -} - -void Exception::AppendMessage(std::optional<StringView> additional_message) { - if (additional_message) AppendMessage(additional_message->ToUtf8()); -} - ErrnoException::ErrnoException() : ErrnoException(NO_MESSAGE) {} ErrnoException::ErrnoException(int errno_code) @@ -52,10 +39,4 @@ ErrnoException::ErrnoException(std::string_view message) ErrnoException::ErrnoException(std::string_view message, int errno_code) : Exception(std::format("{} Errno is {}.", message, errno_code)), errno_code_(errno_code) {} - -ErrnoException::ErrnoException(StringView message) - : ErrnoException(message.ToUtf8()) {} - -ErrnoException::ErrnoException(StringView message, int errno_code) - : ErrnoException(message.ToUtf8(), errno_code) {} } // namespace cru diff --git a/src/base/Format.cpp b/src/base/Format.cpp index cba4137f..e442e572 100644 --- a/src/base/Format.cpp +++ b/src/base/Format.cpp @@ -9,7 +9,7 @@ FormatToken ParsePlaceHolder(String place_holder_string) { if (place_holder_string.StartWith(u":")) { if (place_holder_string.Find(u':', 1) != -1) { - throw Exception(u"Two ':' inside placeholder."); + throw Exception("Two ':' inside placeholder."); } return FormatToken::NonePlaceHolder(place_holder_string.substr(1)); @@ -27,7 +27,7 @@ FormatToken ParsePlaceHolder(String place_holder_string) { if (index != place_holder_string.size()) { if (place_holder_string[index] != ':') { - throw Exception(u"Invalid placeholder in format."); + throw Exception("Invalid placeholder in format."); } option = place_holder_string.substr(index + 1); @@ -68,7 +68,7 @@ std::vector<FormatToken> ParseToFormatTokenList(StringView str) { is_in_place_holder = false; } else { if (is_in_place_holder) { - throw Exception(u"Invalid format string: '{' inside placeholder."); + throw Exception("Invalid format string: '{' inside placeholder."); } try_to_escape = true; @@ -101,7 +101,7 @@ void FormatAppendFromFormatTokenList( for (Index i = index; i < static_cast<Index>(format_token_list.size()); i++) { const auto& token = format_token_list[i]; if (token.type == FormatTokenType::PlaceHolder) { - throw Exception(u"More placeholder than args."); + throw Exception("More placeholder than args."); } else { current += token.data; } diff --git a/src/base/PropertyTree.cpp b/src/base/PropertyTree.cpp index db17f84f..ea47dabc 100644 --- a/src/base/PropertyTree.cpp +++ b/src/base/PropertyTree.cpp @@ -50,7 +50,7 @@ PropertyTree::PropertyTree(std::unordered_map<std::string, std::string> values) std::string PropertyTree::GetValue(const std::string& key) const { auto it = values_.find(key); if (it == values_.end()) { - throw Exception(u"Property tree has no value."); + throw Exception("Property tree has no value."); } return it->second; } diff --git a/src/base/String.cpp b/src/base/String.cpp index 29cebde3..c90b9a71 100644 --- a/src/base/String.cpp +++ b/src/base/String.cpp @@ -324,7 +324,7 @@ void String::AppendCodePoint(CodePoint code_point) { if (!Utf16EncodeCodePointAppend( code_point, std::bind(&String::push_back, this, std::placeholders::_1))) { - throw TextEncodeException(u"Code point out of range."); + throw TextEncodeException("Code point out of range."); } } @@ -623,7 +623,7 @@ float StringView::ParseToFloat(Index* processed_characters_count, } if (flags & StringToNumberFlags::kThrowOnError && std::isnan(result)) { - throw Exception(u"Result of string to float conversion is NaN"); + throw Exception("Result of string to float conversion is NaN"); } return result; @@ -639,7 +639,7 @@ double StringView::ParseToDouble(Index* processed_characters_count, } if (flags & StringToNumberFlags::kThrowOnError && std::isnan(result)) { - throw Exception(u"Result of string to double conversion is NaN"); + throw Exception("Result of string to double conversion is NaN"); } return result; @@ -651,7 +651,7 @@ std::vector<float> StringView::ParseToFloatList(value_type separator) const { for (auto& item : list) { auto value = item.ParseToFloat(); if (std::isnan(value)) { - throw Exception(u"Invalid double value."); + throw Exception("Invalid double value."); } result.push_back(value); } @@ -664,7 +664,7 @@ std::vector<double> StringView::ParseToDoubleList(value_type separator) const { for (auto& item : list) { auto value = item.ParseToDouble(); if (std::isnan(value)) { - throw Exception(u"Invalid double value."); + throw Exception("Invalid double value."); } result.push_back(value); } diff --git a/src/base/StringToNumberConverter.cpp b/src/base/StringToNumberConverter.cpp index 65aec48e..f7516630 100644 --- a/src/base/StringToNumberConverter.cpp +++ b/src/base/StringToNumberConverter.cpp @@ -34,7 +34,7 @@ StringToIntegerResult StringToIntegerConverter::Parse( *processed_characters_count = 0; } if (throw_on_error) { - throw Exception(u"Empty string (after reading leading spaces)."); + throw Exception("Empty string (after reading leading spaces)."); } else { return {false, 0}; } @@ -54,7 +54,7 @@ StringToIntegerResult StringToIntegerConverter::Parse( *processed_characters_count = 0; } if (throw_on_error) { - throw Exception(u"Empty string (after reading sign)."); + throw Exception("Empty string (after reading sign)."); } else { return {false, 0}; } @@ -89,7 +89,7 @@ StringToIntegerResult StringToIntegerConverter::Parse( *processed_characters_count = 0; } if (throw_on_error) { - throw Exception(u"Empty string (after reading head base indicator)."); + throw Exception("Empty string (after reading head base indicator)."); } else { return {false, 0}; } @@ -136,7 +136,7 @@ StringToIntegerResult StringToIntegerConverter::Parse( *processed_characters_count = 0; } if (throw_on_error) { - throw Exception(String(u"Read invalid character '") + c + u"'."); + throw Exception(std::string("Read invalid character '") + c + "'."); } else { return {false, 0}; } @@ -153,7 +153,7 @@ StringToIntegerResult StringToIntegerConverter::Parse( *processed_characters_count = 0; } if (throw_on_error) { - throw Exception(u"There is trailing junk."); + throw Exception("There is trailing junk."); } else { return {false, 0}; } diff --git a/src/base/StringUtil.cpp b/src/base/StringUtil.cpp index 9053f384..6299acc2 100644 --- a/src/base/StringUtil.cpp +++ b/src/base/StringUtil.cpp @@ -17,13 +17,13 @@ CodePoint Utf8NextCodePoint(const char* ptr, Index size, Index current, auto read_next_folowing_code = [ptr, size, ¤t]() -> CodePoint { if (current == size) throw TextEncodeException( - u"Unexpected end when read continuing byte of multi-byte code " + "Unexpected end when read continuing byte of multi-byte code " "point."); const auto u = static_cast<std::uint8_t>(ptr[current]); if (!(u & (1u << 7)) || (u & (1u << 6))) { throw TextEncodeException( - u"Unexpected bad-format (not 0b10xxxxxx) continuing byte of " + "Unexpected bad-format (not 0b10xxxxxx) continuing byte of " "multi-byte code point."); } @@ -36,7 +36,7 @@ CodePoint Utf8NextCodePoint(const char* ptr, Index size, Index current, if ((1u << 4) & cu0) { // 4-length code point if (cu0 & (1u << 3)) { throw TextEncodeException( - u"Unexpected bad-format begin byte (not 0b11110xxx) of 4-byte" + "Unexpected bad-format begin byte (not 0b11110xxx) of 4-byte" "code point."); } @@ -61,7 +61,7 @@ CodePoint Utf8NextCodePoint(const char* ptr, Index size, Index current, } } else { throw TextEncodeException( - u"Unexpected bad-format (0b10xxxxxx) begin byte of a code point."); + "Unexpected bad-format (0b10xxxxxx) begin byte of a code point."); } } else { result = static_cast<CodePoint>(cu0); @@ -86,13 +86,13 @@ CodePoint Utf16NextCodePoint(const char16_t* ptr, Index size, Index current, } else if (IsUtf16SurrogatePairLeading(cu0)) { // 2-length code point if (current >= size) { throw TextEncodeException( - u"Unexpected end when reading second code unit of surrogate pair."); + "Unexpected end when reading second code unit of surrogate pair."); } const auto cu1 = ptr[current++]; if (!IsUtf16SurrogatePairTrailing(cu1)) { throw TextEncodeException( - u"Unexpected bad-range second code unit of surrogate pair."); + "Unexpected bad-range second code unit of surrogate pair."); } const auto s0 = ExtractBits<std::uint16_t, 10, CodePoint>(cu0) << 10; @@ -102,7 +102,7 @@ CodePoint Utf16NextCodePoint(const char16_t* ptr, Index size, Index current, } else { throw TextEncodeException( - u"Unexpected bad-range first code unit of surrogate pair."); + "Unexpected bad-range first code unit of surrogate pair."); } } @@ -125,13 +125,13 @@ CodePoint Utf16PreviousCodePoint(const char16_t* ptr, Index size, Index current, } else if (IsUtf16SurrogatePairTrailing(cu0)) { // 2-length code point if (current <= 0) { throw TextEncodeException( - u"Unexpected end when reading first code unit of surrogate pair."); + "Unexpected end when reading first code unit of surrogate pair."); } const auto cu1 = ptr[--current]; if (!IsUtf16SurrogatePairLeading(cu1)) { throw TextEncodeException( - u"Unexpected bad-range first code unit of surrogate pair."); + "Unexpected bad-range first code unit of surrogate pair."); } const auto s0 = ExtractBits<std::uint16_t, 10, CodePoint>(cu1) << 10; @@ -141,7 +141,7 @@ CodePoint Utf16PreviousCodePoint(const char16_t* ptr, Index size, Index current, } else { throw TextEncodeException( - u"Unexpected bad-range second code unit of surrogate pair."); + "Unexpected bad-range second code unit of surrogate pair."); } } diff --git a/src/base/SubProcess.cpp b/src/base/SubProcess.cpp index 9a6ee64f..964ae478 100644 --- a/src/base/SubProcess.cpp +++ b/src/base/SubProcess.cpp @@ -19,7 +19,7 @@ void PlatformSubProcess::Start() { std::lock_guard lock_guard(this->lock_); if (this->state_->status != SubProcessStatus::Prepare) { - throw SubProcessException(u"The process has already tried to start."); + throw SubProcessException("The process has already tried to start."); } try { @@ -36,8 +36,8 @@ void PlatformSubProcess::Start() { thread.detach(); } catch (const std::exception& e) { this->state_->status = SubProcessStatus::FailedToStart; - throw SubProcessFailedToStartException(u"Sub-process failed to start. " + - String::FromUtf8(e.what())); + throw SubProcessFailedToStartException( + std::string("Sub-process failed to start. ") + e.what()); } } @@ -46,13 +46,12 @@ void PlatformSubProcess::Wait( std::lock_guard lock_guard(this->lock_); if (this->state_->status == SubProcessStatus::Prepare) { - throw SubProcessException( - u"The process does not start. Can't wait for it."); + throw SubProcessException("The process does not start. Can't wait for it."); } if (this->state_->status == SubProcessStatus::FailedToStart) { throw SubProcessException( - u"The process failed to start. Can't wait for it."); + "The process failed to start. Can't wait for it."); } if (this->state_->status == SubProcessStatus::Exited) { @@ -75,11 +74,11 @@ void PlatformSubProcess::Kill() { std::lock_guard lock_guard(this->lock_); if (this->state_->status == SubProcessStatus::Prepare) { - throw SubProcessException(u"The process does not start. Can't kill it."); + throw SubProcessException("The process does not start. Can't kill it."); } if (this->state_->status == SubProcessStatus::FailedToStart) { - throw SubProcessException(u"The process failed to start. Can't kill it."); + throw SubProcessException("The process failed to start. Can't kill it."); } if (this->state_->status == SubProcessStatus::Exited) { @@ -104,17 +103,16 @@ SubProcessExitResult PlatformSubProcess::GetExitResult() { if (this->state_->status == SubProcessStatus::Prepare) { throw SubProcessException( - u"The process does not start. Can't get exit result."); + "The process does not start. Can't get exit result."); } if (this->state_->status == SubProcessStatus::FailedToStart) { throw SubProcessException( - u"The process failed to start. Can't get exit result."); + "The process failed to start. Can't get exit result."); } if (this->state_->status == SubProcessStatus::Running) { - throw SubProcessException( - u"The process is running. Can't get exit result."); + throw SubProcessException("The process is running. Can't get exit result."); } return this->state_->exit_result; @@ -132,8 +130,9 @@ io::Stream* PlatformSubProcess::GetStderrStream() { return this->state_->impl->GetStderrStream(); } -SubProcess SubProcess::Create(String program, std::vector<String> arguments, - std::unordered_map<String, String> environments) { +SubProcess SubProcess::Create( + std::string program, std::vector<std::string> arguments, + std::unordered_map<std::string, std::string> environments) { SubProcessStartInfo start_info; start_info.program = std::move(program); start_info.arguments = std::move(arguments); @@ -142,8 +141,8 @@ SubProcess SubProcess::Create(String program, std::vector<String> arguments, } SubProcessExitResult SubProcess::Call( - String program, std::vector<String> arguments, - std::unordered_map<String, String> environments) { + std::string program, std::vector<std::string> arguments, + std::unordered_map<std::string, std::string> environments) { auto process = Create(std::move(program), std::move(arguments), std::move(environments)); process.Wait(); @@ -151,11 +150,10 @@ SubProcessExitResult SubProcess::Call( } SubProcess::SubProcess(SubProcessStartInfo start_info) { - #ifdef CRU_PLATFORM_UNIX platform_process_.reset(new PlatformSubProcess( - std::move(start_info), - std::make_shared<platform::unix::PosixSpawnSubProcessImpl>())); + std::move(start_info), + std::make_shared<platform::unix::PosixSpawnSubProcessImpl>())); #else NotImplemented(); #endif @@ -203,7 +201,7 @@ void SubProcess::Detach() { auto p = platform_process_.release(); } void SubProcess::CheckValid() const { if (!IsValid()) { - throw SubProcessException(u"SubProcess instance is invalid."); + throw SubProcessException("SubProcess instance is invalid."); } } diff --git a/src/base/io/BufferStream.cpp b/src/base/io/BufferStream.cpp index 57a8b694..0dbb438b 100644 --- a/src/base/io/BufferStream.cpp +++ b/src/base/io/BufferStream.cpp @@ -57,7 +57,7 @@ Index BufferStream::DoWrite(const std::byte* buffer, Index offset, Index size) { if (eof_) { throw WriteAfterEofException( - u"Stream has been set eof. Can't write to it any more."); + "Stream has been set eof. Can't write to it any more."); } condition_variable_.wait(lock, [this] { diff --git a/src/base/io/CFileStream.cpp b/src/base/io/CFileStream.cpp index 45eb2eaf..f0d4790b 100644 --- a/src/base/io/CFileStream.cpp +++ b/src/base/io/CFileStream.cpp @@ -28,7 +28,7 @@ CFileStream::CFileStream(const char* path, const char* mode) file_(std::fopen(path, mode)), auto_close_(true) { if (file_ == nullptr) { - throw ErrnoException(u"Cannot open file."); + throw ErrnoException("Cannot open file."); } } @@ -36,7 +36,7 @@ CFileStream::CFileStream(std::FILE* file, bool readable, bool writable, bool auto_close) : Stream(true, readable, writable), file_(file), auto_close_(auto_close) { if (file_ == nullptr) { - throw Exception(u"File is NULL."); + throw Exception("File is NULL."); } } @@ -55,13 +55,13 @@ static int ConvertOriginFlag(Stream::SeekOrigin origin) { case Stream::SeekOrigin::End: return SEEK_END; default: - throw Exception(u"Unknown seek origin."); + throw Exception("Unknown seek origin."); } } Index CFileStream::DoSeek(Index offset, SeekOrigin origin) { if (std::fseek(file_, offset, ConvertOriginFlag(origin))) { - throw ErrnoException(u"Seek failed."); + throw ErrnoException("Seek failed."); } return DoTell(); } @@ -69,7 +69,7 @@ Index CFileStream::DoSeek(Index offset, SeekOrigin origin) { Index CFileStream::DoTell() { long position = std::ftell(file_); if (position == -1) { - throw ErrnoException(u"Tell failed."); + throw ErrnoException("Tell failed."); } return position; } @@ -91,7 +91,7 @@ void CFileStream::DoFlush() { std::fflush(file_); } void CFileStream::DoClose() { CRU_STREAM_BEGIN_CLOSE if (auto_close_ && !std::fclose(file_)) { - throw Exception(u"Failed to close FILE."); + throw Exception("Failed to close FILE."); } file_ = nullptr; } diff --git a/src/base/io/MemoryStream.cpp b/src/base/io/MemoryStream.cpp index 4c650f3e..bba0e618 100644 --- a/src/base/io/MemoryStream.cpp +++ b/src/base/io/MemoryStream.cpp @@ -14,10 +14,10 @@ MemoryStream::MemoryStream( position_(0), release_func_(std::move(release_func)) { if (!buffer) { - throw Exception(u"Buffer is nullptr"); + throw Exception("Buffer is nullptr"); } if (size <= 0) { - throw Exception(u"Size is 0 or negative."); + throw Exception("Size is 0 or negative."); } } diff --git a/src/base/io/Resource.cpp b/src/base/io/Resource.cpp index e599f8a9..48045e59 100644 --- a/src/base/io/Resource.cpp +++ b/src/base/io/Resource.cpp @@ -49,7 +49,7 @@ std::filesystem::path GetResourceDir() { } } - throw Exception(u"Failed to find resource directory."); + throw Exception("Failed to find resource directory."); #endif diff --git a/src/base/io/Stream.cpp b/src/base/io/Stream.cpp index 4cb58eca..1aafc839 100644 --- a/src/base/io/Stream.cpp +++ b/src/base/io/Stream.cpp @@ -6,28 +6,24 @@ namespace cru::io { StreamOperationNotSupportedException::StreamOperationNotSupportedException( - StringView operation) - : StreamOperationNotSupportedException(operation.ToUtf8()) {} - -StreamOperationNotSupportedException::StreamOperationNotSupportedException( std::string operation) : Exception(std::format("Stream operation {} not supported.", operation)), operation_(std::move(operation)) {} void StreamOperationNotSupportedException::CheckSeek(bool seekable) { - if (!seekable) throw StreamOperationNotSupportedException(u"seek"); + if (!seekable) throw StreamOperationNotSupportedException("seek"); } void StreamOperationNotSupportedException::CheckRead(bool readable) { - if (!readable) throw StreamOperationNotSupportedException(u"read"); + if (!readable) throw StreamOperationNotSupportedException("read"); } void StreamOperationNotSupportedException::CheckWrite(bool writable) { - if (!writable) throw StreamOperationNotSupportedException(u"write"); + if (!writable) throw StreamOperationNotSupportedException("write"); } StreamClosedException::StreamClosedException() - : Exception(u"Stream is already closed.") {} + : Exception("Stream is already closed.") {} void StreamClosedException::Check(bool closed) { if (closed) throw StreamClosedException(); @@ -122,8 +118,8 @@ bool Stream::DoCanSeek() { return *supported_operations_->can_seek; } else { throw Exception( - u"Can seek is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can seek is neither set in supported_operations nor implemeted in " + "virtual function."); } } @@ -132,8 +128,8 @@ bool Stream::DoCanRead() { return *supported_operations_->can_read; } else { throw Exception( - u"Can read is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can read is neither set in supported_operations nor implemeted in " + "virtual function."); } } @@ -142,13 +138,13 @@ bool Stream::DoCanWrite() { return *supported_operations_->can_write; } else { throw Exception( - u"Can write is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can write is neither set in supported_operations nor implemeted in " + "virtual function."); } } Index Stream::DoSeek(Index offset, SeekOrigin origin) { - throw Exception(u"Stream is seekable but DoSeek is not implemented."); + throw Exception("Stream is seekable but DoSeek is not implemented."); } Index Stream::DoTell() { @@ -171,11 +167,11 @@ Index Stream::DoGetSize() { } Index Stream::DoRead(std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is readable but DoRead is not implemented."); + throw Exception("Stream is readable but DoRead is not implemented."); } Index Stream::DoWrite(const std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is writable but DoWrite is not implemented."); + throw Exception("Stream is writable but DoWrite is not implemented."); } void Stream::DoFlush() {} @@ -195,8 +191,8 @@ Buffer Stream::ReadToEnd(Index grow_size) { return buffer; } -String Stream::ReadToEndAsUtf8String() { +std::string Stream::ReadToEndAsUtf8String() { auto buffer = ReadToEnd(); - return String::FromUtf8(buffer); + return std::string(buffer.GetUsedBeginPtr(), buffer.GetUsedEndPtr()); } } // namespace cru::io diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp index f99d3224..7362175f 100644 --- a/src/base/platform/unix/PosixSpawnSubProcess.cpp +++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp @@ -1,7 +1,6 @@ #include "cru/base/platform/unix/PosixSpawnSubProcess.h" #include "cru/base/Exception.h" #include "cru/base/Guard.h" -#include "cru/base/String.h" #include "cru/base/SubProcess.h" #include "cru/base/log/Logger.h" @@ -9,6 +8,7 @@ #include <spawn.h> #include <sys/wait.h> #include <unistd.h> +#include <cstring> #include <format> #include <memory> #include <string_view> @@ -20,23 +20,25 @@ PosixSpawnSubProcessImpl::PosixSpawnSubProcessImpl() : pid_(0), exit_code_(0) {} PosixSpawnSubProcessImpl::~PosixSpawnSubProcessImpl() {} namespace { -char** CreateCstrArray(const std::vector<String>& argv) { - std::vector<Buffer> utf8_argv; - for (const auto& arg : argv) { - utf8_argv.push_back(arg.ToUtf8Buffer()); +char** CreateCstrArray(const std::vector<std::string>& argv) { + auto argv_len = argv.size(); + char** result = new char*[argv_len + 1]; + for (int i = 0; i < argv.size(); i++) { + auto len = argv[i].size(); + char* str = new char[len + 1]; + result[i] = str; + std::memcpy(str, argv[i].data(), len); + str[len] = 0; } - char** result = new char*[utf8_argv.size() + 1]; - for (int i = 0; i < utf8_argv.size(); i++) { - result[i] = reinterpret_cast<char*>(utf8_argv[i].Detach()); - } - result[utf8_argv.size()] = nullptr; + result[argv_len] = nullptr; return result; } -char** CreateCstrArray(const std::unordered_map<String, String>& envp) { - std::vector<String> str_array; +char** CreateCstrArray( + const std::unordered_map<std::string, std::string>& envp) { + std::vector<std::string> str_array; for (auto& [key, value] : envp) { - str_array.push_back(key + u"=" + value); + str_array.push_back(key + "=" + value); } return CreateCstrArray(str_array); } @@ -112,8 +114,8 @@ void PosixSpawnSubProcessImpl::PlatformCreateProcess( "Failed to set flag POSIX_SPAWN_CLOEXEC_DEFAULT (osx)."); #endif - auto exe = start_info.program.ToUtf8(); - std::vector<String> arguments{start_info.program}; + auto exe = start_info.program; + std::vector<std::string> arguments{start_info.program}; arguments.insert(arguments.cend(), start_info.arguments.cbegin(), start_info.arguments.cend()); @@ -168,7 +170,7 @@ void PosixSpawnSubProcessImpl::PlatformKillProcess() { int error = kill(pid_, SIGKILL); if (error != 0) { std::unique_ptr<ErrnoException> inner(new ErrnoException(errno)); - throw SubProcessInternalException(u"Failed to call kill on a subprocess.", + throw SubProcessInternalException("Failed to call kill on a subprocess.", std::move(inner)); } } diff --git a/src/base/platform/unix/UnixFileStream.cpp b/src/base/platform/unix/UnixFileStream.cpp index 0772c279..43ff2244 100644 --- a/src/base/platform/unix/UnixFileStream.cpp +++ b/src/base/platform/unix/UnixFileStream.cpp @@ -33,7 +33,7 @@ int MapSeekOrigin(Stream::SeekOrigin origin) { case Stream::SeekOrigin::End: return SEEK_END; default: - throw Exception(u"Invalid seek origin."); + throw Exception("Invalid seek origin."); } } } // namespace @@ -58,7 +58,7 @@ UnixFileStream::~UnixFileStream() { DoClose(); } Index UnixFileStream::DoSeek(Index offset, SeekOrigin origin) { off_t result = ::lseek(file_descriptor_, offset, MapSeekOrigin(origin)); if (result == -1) { - throw ErrnoException(u"Failed to seek file."); + throw ErrnoException("Failed to seek file."); } return result; } @@ -66,7 +66,7 @@ Index UnixFileStream::DoSeek(Index offset, SeekOrigin origin) { Index UnixFileStream::DoRead(std::byte *buffer, Index offset, Index size) { auto result = ::read(file_descriptor_, buffer + offset, size); if (result == -1) { - throw ErrnoException(u"Failed to read file."); + throw ErrnoException("Failed to read file."); } return result; } @@ -75,7 +75,7 @@ Index UnixFileStream::DoWrite(const std::byte *buffer, Index offset, Index size) { auto result = ::write(file_descriptor_, buffer + offset, size); if (result == -1) { - throw ErrnoException(u"Failed to write file."); + throw ErrnoException("Failed to write file."); } return result; } diff --git a/src/base/platform/win/Win32FileStream.cpp b/src/base/platform/win/Win32FileStream.cpp index f3809b3e..341fe9d3 100644 --- a/src/base/platform/win/Win32FileStream.cpp +++ b/src/base/platform/win/Win32FileStream.cpp @@ -29,7 +29,7 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags) if (flags & io::OpenFileFlags::Write) { grfMode |= STGM_WRITE; } else { - throw Exception(u"Stream must be readable or writable."); + throw Exception("Stream must be readable or writable."); } } @@ -80,7 +80,7 @@ Index Win32FileStream::DoRead(std::byte* buffer, Index offset, Index size) { Index Win32FileStream::DoWrite(const std::byte* buffer, Index offset, Index size) { if (size < 0) { - throw Exception(u"Size must be greater than 0."); + throw Exception("Size must be greater than 0."); } CheckClosed(); diff --git a/src/platform/Exception.cpp b/src/platform/Exception.cpp index 744404e0..6a718f63 100644 --- a/src/platform/Exception.cpp +++ b/src/platform/Exception.cpp @@ -17,15 +17,6 @@ PlatformNotMatchException::PlatformNotMatchException( AppendMessage(additional_message); } -PlatformNotMatchException::PlatformNotMatchException( - StringView resource_platform, StringView target_platform, - std::optional<StringView> additional_message) - : PlatformNotMatchException( - resource_platform.ToUtf8(), target_platform.ToUtf8(), - additional_message.has_value() - ? std::make_optional(additional_message->ToUtf8()) - : std::nullopt) {} - PlatformNotMatchException::~PlatformNotMatchException() {} PlatformUnsupportedException::PlatformUnsupportedException( @@ -39,23 +30,5 @@ PlatformUnsupportedException::PlatformUnsupportedException( AppendMessage(additional_message); } -PlatformUnsupportedException::PlatformUnsupportedException( - StringView platform, StringView operation, - std::optional<StringView> additional_message) - : PlatformUnsupportedException( - platform.ToUtf8(), operation.ToUtf8(), - additional_message.has_value() - ? std::make_optional(additional_message->ToUtf8()) - : std::nullopt) {} - PlatformUnsupportedException::~PlatformUnsupportedException() {} - -String PlatformUnsupportedException::GetPlatform() const { - return String::FromUtf8(platform_); -} - -String PlatformUnsupportedException::GetOperation() const { - return String::FromUtf8(operation_); -} - } // namespace cru::platform diff --git a/src/platform/graphics/Geometry.cpp b/src/platform/graphics/Geometry.cpp index b9503c4e..2c842a6e 100644 --- a/src/platform/graphics/Geometry.cpp +++ b/src/platform/graphics/Geometry.cpp @@ -15,9 +15,9 @@ bool IGeometry::StrokeContains(float width, const Point& point) { std::unique_ptr<IGeometry> IGeometry::CreateStrokeGeometry( [[maybe_unused]] float width) { - throw PlatformUnsupportedException(GetPlatformId(), u"CreateStrokeGeometry", - u"Create stroke geometry of a geometry is " - u"not supported on this platform."); + throw PlatformUnsupportedException(GetPlatformIdUtf8(), "CreateStrokeGeometry", + "Create stroke geometry of a geometry is " + "not supported on this platform."); } void IGeometryBuilder::RelativeMoveTo(const Point& offset) { @@ -227,7 +227,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) { auto read_number = [&] { if (read_spaces()) { - throw Exception(u"Unexpected eof of svg path data command."); + throw Exception("Unexpected eof of svg path data command."); } if (path_d[position] == ',') { @@ -239,7 +239,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) { auto result = path_d.substr(position).ParseToFloat( &processed_count, StringToNumberFlags::kAllowTrailingJunk); - if (std::isnan(result)) throw Exception(u"Invalid svg path data number."); + if (std::isnan(result)) throw Exception("Invalid svg path data number."); position += processed_count; @@ -415,7 +415,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) { CloseFigure(true); break; default: - throw Exception(u"Invalid svg path command."); + throw Exception("Invalid svg path command."); } return true; }; diff --git a/src/platform/graphics/SvgGeometryBuilderMixin.cpp b/src/platform/graphics/SvgGeometryBuilderMixin.cpp index bf5275c5..73290da5 100644 --- a/src/platform/graphics/SvgGeometryBuilderMixin.cpp +++ b/src/platform/graphics/SvgGeometryBuilderMixin.cpp @@ -10,8 +10,8 @@ SvgGeometryBuilderMixin::~SvgGeometryBuilderMixin() {} Point SvgGeometryBuilderMixin::GetCurrentPosition() { throw PlatformUnsupportedException( - GetPlatformId(), u"GetCurrentPosition", - u"Svg-based geometry does not support get current position."); + GetPlatformIdUtf8(), "GetCurrentPosition", + "Svg-based geometry does not support get current position."); } void SvgGeometryBuilderMixin::MoveTo(const Point& point) { diff --git a/src/platform/graphics/cairo/CairoGeometry.cpp b/src/platform/graphics/cairo/CairoGeometry.cpp index 2d415884..1f680c34 100644 --- a/src/platform/graphics/cairo/CairoGeometry.cpp +++ b/src/platform/graphics/cairo/CairoGeometry.cpp @@ -72,7 +72,7 @@ std::unique_ptr<IGeometry> CairoGeometry::Transform(const Matrix& matrix) { } std::unique_ptr<IGeometry> CairoGeometry::CreateStrokeGeometry(float width) { - throw Exception(u"Not implemented"); + throw Exception("Not implemented"); } CairoGeometryBuilder::CairoGeometryBuilder(CairoGraphicsFactory* factory) diff --git a/src/platform/graphics/cairo/CairoImageFactory.cpp b/src/platform/graphics/cairo/CairoImageFactory.cpp index 912226d9..ff922e77 100644 --- a/src/platform/graphics/cairo/CairoImageFactory.cpp +++ b/src/platform/graphics/cairo/CairoImageFactory.cpp @@ -207,19 +207,19 @@ std::unique_ptr<IImage> CairoImageFactory::DecodeFromStream( return DecodePng(GetCairoGraphicsFactory(), stream); } - throw Exception(u"Image format unknown. Currently only support png."); + throw Exception("Image format unknown. Currently only support png."); } void CairoImageFactory::EncodeToStream(IImage* image, io::Stream* stream, ImageFormat format, float quality) { - auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId()); + auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8()); if (format == ImageFormat::Png) { EncodePng(cairo_image->GetCairoSurface(), stream); return; } - throw Exception(u"Not implemented. Currently only support png."); + throw Exception("Not implemented. Currently only support png."); } std::unique_ptr<IImage> CairoImageFactory::CreateBitmap(int width, int height) { diff --git a/src/platform/graphics/cairo/CairoPainter.cpp b/src/platform/graphics/cairo/CairoPainter.cpp index b9babaa2..94111098 100644 --- a/src/platform/graphics/cairo/CairoPainter.cpp +++ b/src/platform/graphics/cairo/CairoPainter.cpp @@ -56,7 +56,7 @@ void CairoPainter::Clear(const Color& color) { void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush, float width) { CheckValidation(); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); cairo_set_source(cairo_, cairo_pattern); @@ -71,7 +71,7 @@ void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush, void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush, float width) { CheckValidation(); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); cairo_set_source(cairo_, cairo_pattern); @@ -85,7 +85,7 @@ void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush, void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) { CheckValidation(); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); cairo_set_source(cairo_, cairo_pattern); @@ -99,7 +99,7 @@ void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) { void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush, float width) { CheckValidation(); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); cairo_set_source(cairo_, cairo_pattern); @@ -122,7 +122,7 @@ void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush, void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) { CheckValidation(); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); cairo_set_source(cairo_, cairo_pattern); @@ -145,8 +145,8 @@ void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) { void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) { CheckValidation(); - auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId()); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_path = cairo_geometry->GetCairoPath(); auto cairo_pattern = cairo_brush->GetCairoPattern(); @@ -162,8 +162,8 @@ void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush, void CairoPainter::FillGeometry(IGeometry* geometry, IBrush* brush) { CheckValidation(); - auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId()); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_path = cairo_geometry->GetCairoPath(); auto cairo_pattern = cairo_brush->GetCairoPattern(); @@ -181,9 +181,9 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout, CheckValidation(); auto pango_text_layout = - CheckPlatform<PangoTextLayout>(text_layout, GetPlatformId()); + CheckPlatform<PangoTextLayout>(text_layout, GetPlatformIdUtf8()); - auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId()); + auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8()); auto cairo_pattern = cairo_brush->GetCairoPattern(); cairo_save(cairo_); @@ -196,7 +196,7 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout, void CairoPainter::DrawImage(const Point& offset, IImage* image) { CheckValidation(); - auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId()); + auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8()); cairo_save(cairo_); cairo_set_source_surface(cairo_, cairo_image->GetCairoSurface(), 0, 0); cairo_new_path(cairo_); @@ -251,7 +251,7 @@ void CairoPainter::EndDraw() { void CairoPainter::CheckValidation() { if (!valid_) { - throw ReuseException(u"Painter already ended drawing."); + throw ReuseException("Painter already ended drawing."); } } } // namespace cru::platform::graphics::cairo diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp index 8dfd59d5..746056e2 100644 --- a/src/platform/graphics/cairo/PangoTextLayout.cpp +++ b/src/platform/graphics/cairo/PangoTextLayout.cpp @@ -24,7 +24,7 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory, std::shared_ptr<IFont> font) : CairoResource(factory) { Expects(font); - font_ = CheckPlatform<PangoFont>(font, GetPlatformId()); + font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8()); pango_layout_ = pango_cairo_create_layout(factory->GetDefaultCairo()); pango_layout_set_font_description(pango_layout_, font_->GetPangoFontDescription()); @@ -44,7 +44,7 @@ std::shared_ptr<IFont> PangoTextLayout::GetFont() { return font_; } void PangoTextLayout::SetFont(std::shared_ptr<IFont> font) { Expects(font); - font_ = CheckPlatform<PangoFont>(font, GetPlatformId()); + font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8()); pango_layout_set_font_description(pango_layout_, font_->GetPangoFontDescription()); } diff --git a/src/platform/graphics/direct2d/Geometry.cpp b/src/platform/graphics/direct2d/Geometry.cpp index a2377400..45971b76 100644 --- a/src/platform/graphics/direct2d/Geometry.cpp +++ b/src/platform/graphics/direct2d/Geometry.cpp @@ -17,7 +17,7 @@ D2DGeometryBuilder::D2DGeometryBuilder(DirectGraphicsFactory* factory) void D2DGeometryBuilder::CheckValidation() { if (!IsValid()) - throw ReuseException(u"The geometry builder is already disposed."); + throw ReuseException("The geometry builder is already disposed."); } Point D2DGeometryBuilder::GetCurrentPosition() { diff --git a/src/platform/graphics/direct2d/ImageFactory.cpp b/src/platform/graphics/direct2d/ImageFactory.cpp index 113f70c8..b9e9221a 100644 --- a/src/platform/graphics/direct2d/ImageFactory.cpp +++ b/src/platform/graphics/direct2d/ImageFactory.cpp @@ -67,14 +67,14 @@ GUID ConvertImageFormatToGUID(ImageFormat format) { format_guid = GUID_ContainerFormatGif; break; default: - throw Exception(u"Unknown image format"); + throw Exception("Unknown image format"); } return format_guid; } void WinImageFactory::EncodeToStream(IImage* image, io::Stream* stream, ImageFormat format, float quality) { - auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformId()); + auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8()); Microsoft::WRL::ComPtr<IStream> com_stream( platform::win::ConvertStreamToComStream(stream)); @@ -139,8 +139,8 @@ void WinImageFactory::EncodeToStream(IImage* image, io::Stream* stream, } std::unique_ptr<IImage> WinImageFactory::CreateBitmap(int width, int height) { - if (width <= 0) throw Exception(u"Bitmap width must be greater than 0."); - if (height <= 0) throw Exception(u"Bitmap height must be greater than 0."); + if (width <= 0) throw Exception("Bitmap width must be greater than 0."); + if (height <= 0) throw Exception("Bitmap height must be greater than 0."); auto graphics_factory = GetDirectFactory(); diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp index a505e46e..29ddcabb 100644 --- a/src/platform/graphics/direct2d/Painter.cpp +++ b/src/platform/graphics/direct2d/Painter.cpp @@ -55,7 +55,7 @@ void D2DDeviceContextPainter::Clear(const Color& color) { void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end, IBrush* brush, float width) { CheckValidation(); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->DrawLine(Convert(start), Convert(end), b->GetD2DBrushInterface(), width); } @@ -63,7 +63,7 @@ void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end, void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush, float width) { CheckValidation(); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->DrawRectangle(Convert(rectangle), b->GetD2DBrushInterface(), width); } @@ -71,14 +71,14 @@ void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle, void D2DDeviceContextPainter::FillRectangle(const Rect& rectangle, IBrush* brush) { CheckValidation(); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->FillRectangle(Convert(rectangle), b->GetD2DBrushInterface()); } void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush, float width) { CheckValidation(); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->DrawEllipse( D2D1::Ellipse(Convert(outline_rect.GetCenter()), outline_rect.width / 2.0f, outline_rect.height / 2.0f), @@ -87,7 +87,7 @@ void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect, void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) { CheckValidation(); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->FillEllipse( D2D1::Ellipse(Convert(outline_rect.GetCenter()), outline_rect.width / 2.0f, outline_rect.height / 2.0f), @@ -97,16 +97,16 @@ void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect, void D2DDeviceContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) { CheckValidation(); - const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId()); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->DrawGeometry(g->GetComInterface(), b->GetD2DBrushInterface(), width); } void D2DDeviceContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) { CheckValidation(); - const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId()); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->FillGeometry(g->GetComInterface(), b->GetD2DBrushInterface()); } @@ -115,15 +115,15 @@ void D2DDeviceContextPainter::DrawText(const Point& offset, ITextLayout* text_layout, IBrush* brush) { CheckValidation(); - const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformId()); - const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId()); + const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformIdUtf8()); + const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8()); device_context_->DrawTextLayout(Convert(offset), t->GetComInterface(), b->GetD2DBrushInterface()); } void D2DDeviceContextPainter::DrawImage(const Point& offset, IImage* image) { CheckValidation(); - const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformId()); + const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8()); Microsoft::WRL::ComPtr<ID2D1DeviceContext> device_context; @@ -177,7 +177,7 @@ void D2DDeviceContextPainter::EndDraw() { void D2DDeviceContextPainter::CheckValidation() { if (!is_drawing_) { throw cru::platform::ReuseException( - u"Can't do that on painter after end drawing."); + "Can't do that on painter after end drawing."); } } } // namespace cru::platform::graphics::direct2d diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp index 06bbcaa6..7a2074ec 100644 --- a/src/platform/graphics/direct2d/TextLayout.cpp +++ b/src/platform/graphics/direct2d/TextLayout.cpp @@ -14,7 +14,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphicsFactory* factory, std::shared_ptr<IFont> font, String text) : DirectGraphicsResource(factory), text_(std::move(text)) { Expects(font); - font_ = CheckPlatform<DWriteFont>(font, GetPlatformId()); + font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8()); ThrowIfFailed(factory->GetDWriteFactory()->CreateTextLayout( reinterpret_cast<const wchar_t*>(text_.c_str()), @@ -39,7 +39,7 @@ std::shared_ptr<IFont> DWriteTextLayout::GetFont() { } void DWriteTextLayout::SetFont(std::shared_ptr<IFont> font) { - font_ = CheckPlatform<DWriteFont>(font, GetPlatformId()); + font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8()); ThrowIfFailed(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout( reinterpret_cast<const wchar_t*>(text_.c_str()), static_cast<UINT32>(text_.size()), font_->GetComInterface(), max_width_, diff --git a/src/platform/graphics/quartz/Factory.cpp b/src/platform/graphics/quartz/Factory.cpp index 862c0966..5d5b48b5 100644 --- a/src/platform/graphics/quartz/Factory.cpp +++ b/src/platform/graphics/quartz/Factory.cpp @@ -33,7 +33,7 @@ std::unique_ptr<IFont> QuartzGraphicsFactory::CreateFont(String font_family, std::unique_ptr<ITextLayout> QuartzGraphicsFactory::CreateTextLayout( std::shared_ptr<IFont> font, String text) { - auto f = CheckPlatform<OsxCTFont>(font, GetPlatformId()); + auto f = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8()); return std::make_unique<OsxCTTextLayout>(this, f, text); } diff --git a/src/platform/graphics/quartz/Image.cpp b/src/platform/graphics/quartz/Image.cpp index 966ce6be..d4ccd416 100644 --- a/src/platform/graphics/quartz/Image.cpp +++ b/src/platform/graphics/quartz/Image.cpp @@ -35,7 +35,7 @@ std::unique_ptr<IImage> QuartzImage::CreateWithRect(const Rect& rect) { std::unique_ptr<IPainter> QuartzImage::CreatePainter() { if (!buffer_) throw Exception( - u"Failed to create painter for image because failed to get its " + "Failed to create painter for image because failed to get its " u"buffer."); auto width = CGImageGetWidth(image_); diff --git a/src/platform/graphics/quartz/ImageFactory.cpp b/src/platform/graphics/quartz/ImageFactory.cpp index 93e452e1..62229bcb 100644 --- a/src/platform/graphics/quartz/ImageFactory.cpp +++ b/src/platform/graphics/quartz/ImageFactory.cpp @@ -39,17 +39,17 @@ static String GetImageFormatUniformTypeIdentifier(ImageFormat format) { case ImageFormat::Gif: return u"com.compuserve.gif"; default: - throw Exception(u"Unknown image format."); + throw Exception("Unknown image format."); } } void QuartzImageFactory::EncodeToStream(IImage* image, io::Stream* stream, ImageFormat format, float quality) { if (quality <= 0 || quality > 1) { - throw Exception(u"Invalid quality value."); + throw Exception("Invalid quality value."); } - auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformId()); + auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8()); auto cg_image = quartz_image->GetCGImage(); auto uti = ToCFString(GetImageFormatUniformTypeIdentifier(format)); @@ -67,7 +67,7 @@ void QuartzImageFactory::EncodeToStream(IImage* image, io::Stream* stream, CGImageDestinationAddImage(destination, cg_image, properties); if (!CGImageDestinationFinalize(destination)) { - throw Exception(u"Failed to finalize image destination."); + throw Exception("Failed to finalize image destination."); } CFRelease(quality_wrap); @@ -78,8 +78,8 @@ void QuartzImageFactory::EncodeToStream(IImage* image, io::Stream* stream, std::unique_ptr<IImage> QuartzImageFactory::CreateBitmap(int width, int height) { - if (width <= 0) throw Exception(u"Image width should be greater than 0."); - if (height <= 0) throw Exception(u"Image height should be greater than 0."); + if (width <= 0) throw Exception("Image width should be greater than 0."); + if (height <= 0) throw Exception("Image height should be greater than 0."); CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); diff --git a/src/platform/graphics/quartz/Painter.cpp b/src/platform/graphics/quartz/Painter.cpp index 69e187c3..fe0f5d43 100644 --- a/src/platform/graphics/quartz/Painter.cpp +++ b/src/platform/graphics/quartz/Painter.cpp @@ -66,7 +66,7 @@ void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end, CGContextMoveToPoint(cg_context_, start.x, start.y); CGContextAddLineToPoint(cg_context_, end.x, end.y); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); SetLineWidth(width); @@ -77,7 +77,7 @@ void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush, float width) { Validate(); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width); } @@ -86,7 +86,7 @@ void QuartzCGContextPainter::FillRectangle(const Rect& rectangle, IBrush* brush) { Validate(); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); CGContextFillRect(cg_context_, Convert(rectangle)); } @@ -95,7 +95,7 @@ void QuartzCGContextPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush, float width) { Validate(); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); SetLineWidth(width); @@ -106,7 +106,7 @@ void QuartzCGContextPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) { Validate(); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); CGContextFillEllipseInRect(cg_context_, Convert(outline_rect)); } @@ -115,8 +115,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) { Validate(); - QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId()); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); SetLineWidth(width); @@ -129,8 +129,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush, void QuartzCGContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) { Validate(); - QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId()); - QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId()); + QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8()); + QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8()); b->Select(cg_context_); CGContextBeginPath(cg_context_); @@ -142,7 +142,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset, ITextLayout* text_layout, IBrush* brush) { Validate(); - auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformId()); + auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformIdUtf8()); Color color; @@ -169,7 +169,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset, void QuartzCGContextPainter::DrawImage(const Point& offset, IImage* image) { Validate(); - auto i = CheckPlatform<QuartzImage>(image, GetPlatformId()); + auto i = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8()); auto cg_image = i->GetCGImage(); @@ -225,6 +225,6 @@ void QuartzCGContextPainter::DoEndDraw() { void QuartzCGContextPainter::Validate() { if (cg_context_ == nullptr) - throw ReuseException(u"QuartzCGContextPainter has already be released."); + throw ReuseException("QuartzCGContextPainter has already be released."); } } // namespace cru::platform::graphics::quartz diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp index 8c573c7a..41a2f176 100644 --- a/src/platform/graphics/quartz/TextLayout.cpp +++ b/src/platform/graphics/quartz/TextLayout.cpp @@ -31,7 +31,7 @@ OsxCTTextLayout::~OsxCTTextLayout() { } void OsxCTTextLayout::SetFont(std::shared_ptr<IFont> font) { - font_ = CheckPlatform<OsxCTFont>(font, GetPlatformId()); + font_ = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8()); RecreateFrame(); } diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp index c9184165..f928de35 100644 --- a/src/platform/graphics/web_canvas/Painter.cpp +++ b/src/platform/graphics/web_canvas/Painter.cpp @@ -94,7 +94,7 @@ void WebCanvasPainter::SetFillStyle(IBrush* brush) { } WebCanvasBrush* WebCanvasPainter::ConvertBrush(IBrush* brush) const { - return CheckPlatform<WebCanvasBrush>(brush, GetPlatformId()); + return CheckPlatform<WebCanvasBrush>(brush, GetPlatformIdUtf8()); } WebCanvasRef WebCanvasPainter::GetCanvas() { diff --git a/src/platform/gui/UiApplication.cpp b/src/platform/gui/UiApplication.cpp index 7bc27847..ac93a57d 100644 --- a/src/platform/gui/UiApplication.cpp +++ b/src/platform/gui/UiApplication.cpp @@ -24,11 +24,11 @@ IMenu* IUiApplication::GetApplicationMenu() { return nullptr; } std::optional<String> IUiApplication::ShowSaveDialog( SaveDialogOptions options) { - throw Exception(u"Not implemented."); + throw Exception("Not implemented."); } std::optional<std::vector<String>> IUiApplication::ShowOpenDialog( OpenDialogOptions options) { - throw Exception(u"Not implemented."); + throw Exception("Not implemented."); } } // namespace cru::platform::gui diff --git a/src/platform/gui/osx/Cursor.mm b/src/platform/gui/osx/Cursor.mm index ec364fa7..9c25fdbd 100644 --- a/src/platform/gui/osx/Cursor.mm +++ b/src/platform/gui/osx/Cursor.mm @@ -24,7 +24,7 @@ OsxCursorPrivate::OsxCursorPrivate(OsxCursor* cursor, SystemCursorType cursor_ty ns_cursor_ = [NSCursor IBeamCursor]; break; default: - throw Exception(u"Unknown system cursor type."); + throw Exception("Unknown system cursor type."); } } @@ -87,7 +87,7 @@ std::shared_ptr<ICursor> OsxCursorManager::GetSystemCursor(SystemCursorType type case SystemCursorType::IBeam: return p_->ibeam_cursor_; default: - throw Exception(u"Unknown system cursor type."); + throw Exception("Unknown system cursor type."); } } } // namespace cru::platform::gui::osx diff --git a/src/platform/gui/osx/Keyboard.mm b/src/platform/gui/osx/Keyboard.mm index 8a419009..da4c85f0 100644 --- a/src/platform/gui/osx/Keyboard.mm +++ b/src/platform/gui/osx/Keyboard.mm @@ -260,7 +260,7 @@ NSString* ConvertKeyCodeToKeyEquivalent(KeyCode key_code) { CRU_DEFINE_KEYCODE_MAP(KeyCode::Backspace, @"\x08") CRU_DEFINE_KEYCODE_MAP(KeyCode::Delete, @"\x7F") default: - throw Exception(u"Failed to convert key code to key equivalent string."); + throw Exception("Failed to convert key code to key equivalent string."); } #undef CRU_DEFINE_KEYCODE_MAP } diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm index 6559cf70..7381ca55 100644 --- a/src/platform/gui/osx/Window.mm +++ b/src/platform/gui/osx/Window.mm @@ -64,7 +64,7 @@ void OsxWindowPrivate::OnWindowWillClose() { bool quit = true; for (auto window : all_window) { - auto w = CheckPlatform<OsxWindow>(window, osx_window_->GetPlatformId()); + auto w = CheckPlatform<OsxWindow>(window, osx_window_->GetPlatformIdUtf8()); if (w->p_->window_) { quit = false; break; @@ -179,7 +179,7 @@ void OsxWindowPrivate::CreateWindow() { [window_ setDelegate:window_delegate_]; if (parent_) { - auto parent = CheckPlatform<OsxWindow>(parent_, this->osx_window_->GetPlatformId()); + auto parent = CheckPlatform<OsxWindow>(parent_, this->osx_window_->GetPlatformIdUtf8()); [window_ setParentWindow:parent->p_->window_]; } @@ -231,7 +231,7 @@ void OsxWindow::Close() { INativeWindow* OsxWindow::GetParent() { return p_->parent_; } void OsxWindow::SetParent(INativeWindow* parent) { - auto p = CheckPlatform<OsxWindow>(parent, GetPlatformId()); + auto p = CheckPlatform<OsxWindow>(parent, GetPlatformIdUtf8()); p_->parent_ = parent; @@ -366,7 +366,7 @@ bool OsxWindow::CaptureMouse() { return true; } bool OsxWindow::ReleaseMouse() { return true; } void OsxWindow::SetCursor(std::shared_ptr<ICursor> cursor) { - p_->cursor_ = CheckPlatform<OsxCursor>(cursor, GetPlatformId()); + p_->cursor_ = CheckPlatform<OsxCursor>(cursor, GetPlatformIdUtf8()); p_->UpdateCursor(); } diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index eeb2cde4..5739d0f3 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -79,7 +79,7 @@ void WinNativeWindow::Close() { } void WinNativeWindow::SetParent(INativeWindow* parent) { - auto p = CheckPlatform<WinNativeWindow>(parent, GetPlatformId()); + auto p = CheckPlatform<WinNativeWindow>(parent, GetPlatformIdUtf8()); parent_window_ = p; if (hwnd_) { @@ -228,7 +228,7 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) { throw std::runtime_error("Can't use a nullptr as cursor."); } - cursor_ = CheckPlatform<WinCursor>(cursor, GetPlatformId()); + cursor_ = CheckPlatform<WinCursor>(cursor, GetPlatformIdUtf8()); if (hwnd_) return; diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp index 6a5857fc..6458046b 100644 --- a/src/platform/gui/xcb/Window.cpp +++ b/src/platform/gui/xcb/Window.cpp @@ -271,7 +271,7 @@ bool XcbWindow::ReleaseMouse() { void XcbWindow::SetCursor(std::shared_ptr<ICursor> cursor) { if (!xcb_window_) return; - auto xcb_cursor = CheckPlatform<XcbCursor>(cursor, GetPlatformId()); + auto xcb_cursor = CheckPlatform<XcbCursor>(cursor, GetPlatformIdUtf8()); cursor_ = xcb_cursor; DoSetCursor(*xcb_window_, xcb_cursor.get()); } diff --git a/src/toml/TomlParser.cpp b/src/toml/TomlParser.cpp index 7c29e0be..14442c3c 100644 --- a/src/toml/TomlParser.cpp +++ b/src/toml/TomlParser.cpp @@ -31,7 +31,7 @@ void TomlParser::DoParse(TomlDocument& document) { auto equal_index = line.Find(u'='); if (equal_index == -1) { - throw TomlParsingException(u"Invalid TOML line: " + line); + throw TomlParsingException("Invalid TOML line: " + line.ToUtf8()); } auto key = line.substr(0, equal_index).Trim(); diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index c1b2167e..a95900b4 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -21,7 +21,7 @@ ThemeManager::ThemeManager() { cru::io::GetResourceDir() / "cru/ui/DefaultResources.xml"; if (!std::filesystem::exists(resourses_file)) { - throw Exception(u"Default resources file not found."); + throw Exception("Default resources file not found."); } PrependThemeResourceDictionary( diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp index 421723f5..4bf3d691 100644 --- a/src/ui/ThemeResourceDictionary.cpp +++ b/src/ui/ThemeResourceDictionary.cpp @@ -10,7 +10,7 @@ std::unique_ptr<ThemeResourceDictionary> ThemeResourceDictionary::FromFile( const String& file_path) { io::CFileStream stream(file_path.ToUtf8().c_str(), "r"); auto xml_string = stream.ReadToEndAsUtf8String(); - auto parser = xml::XmlParser(xml_string); + auto parser = xml::XmlParser(String::FromUtf8(xml_string)); return std::make_unique<ThemeResourceDictionary>(parser.Parse(), false); } @@ -25,7 +25,7 @@ ThemeResourceDictionary::~ThemeResourceDictionary() = default; void ThemeResourceDictionary::UpdateResourceMap(xml::XmlElementNode* xml_root) { if (!xml_root->GetTag().CaseInsensitiveEqual(u"Theme")) { - throw Exception(u"Root tag of theme must be 'Theme'."); + throw Exception("Root tag of theme must be 'Theme'."); } for (auto child : xml_root->GetChildren()) { @@ -34,10 +34,10 @@ void ThemeResourceDictionary::UpdateResourceMap(xml::XmlElementNode* xml_root) { if (c->GetTag().CaseInsensitiveEqual(u"Resource")) { auto key_attr = c->GetOptionalAttributeValueCaseInsensitive(u"key"); if (!key_attr) { - throw Exception(u"'key' attribute is required for resource."); + throw Exception("'key' attribute is required for resource."); } if (c->GetChildElementCount() != 1) { - throw Exception(u"Resource must have only one child element."); + throw Exception("Resource must have only one child element."); } ResourceEntry entry; diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp index 6f7de7fb..72ea1ce2 100644 --- a/src/ui/mapper/ColorMapper.cpp +++ b/src/ui/mapper/ColorMapper.cpp @@ -8,7 +8,7 @@ bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { Color ColorMapper::DoMapFromString(String str) { auto c = Color::Parse(str); if (!c) { - throw Exception(u"Invalid color value."); + throw Exception("Invalid color value."); } return *c; } diff --git a/src/ui/mapper/CursorMapper.cpp b/src/ui/mapper/CursorMapper.cpp index ed3c91ec..4f59439f 100644 --- a/src/ui/mapper/CursorMapper.cpp +++ b/src/ui/mapper/CursorMapper.cpp @@ -24,7 +24,7 @@ std::shared_ptr<ICursor> CursorMapper::DoMapFromString(String str) { } else if (str.CaseInsensitiveCompare(u"ibeam") == 0) { return cursor_manager->GetSystemCursor(SystemCursorType::IBeam); } else { - throw Exception(u"Unsupported cursor type."); + throw Exception("Unsupported cursor type."); } } diff --git a/src/ui/mapper/MapperRegistry.cpp b/src/ui/mapper/MapperRegistry.cpp index a542bfca..d877f14a 100644 --- a/src/ui/mapper/MapperRegistry.cpp +++ b/src/ui/mapper/MapperRegistry.cpp @@ -74,7 +74,7 @@ MapperRegistry::~MapperRegistry() { void MapperRegistry::RegisterMapper(MapperBase *mapper) { if (std::find(mapper_list_.cbegin(), mapper_list_.cend(), mapper) != mapper_list_.cend()) { - throw Exception(u"This mapper is already registered."); + throw Exception("This mapper is already registered."); } mapper_list_.push_back(mapper); @@ -83,7 +83,7 @@ void MapperRegistry::RegisterMapper(MapperBase *mapper) { void MapperRegistry::UnregisterMapper(MapperBase *mapper) { auto it = std::find(mapper_list_.begin(), mapper_list_.end(), mapper); if (it == mapper_list_.end()) { - throw Exception(u"This mapper is not registered."); + throw Exception("This mapper is not registered."); } mapper_list_.erase(it); diff --git a/src/ui/mapper/PointMapper.cpp b/src/ui/mapper/PointMapper.cpp index 4b0104d0..1bf7defb 100644 --- a/src/ui/mapper/PointMapper.cpp +++ b/src/ui/mapper/PointMapper.cpp @@ -12,7 +12,7 @@ Point PointMapper::DoMapFromString(String str) { } else if (values.size() == 1) { return {values[0], values[0]}; } else { - throw Exception(u"Invalid Point string."); + throw Exception("Invalid Point string."); } } diff --git a/src/ui/mapper/SizeMapper.cpp b/src/ui/mapper/SizeMapper.cpp index 4cbe2d38..7e1bbd91 100644 --- a/src/ui/mapper/SizeMapper.cpp +++ b/src/ui/mapper/SizeMapper.cpp @@ -12,7 +12,7 @@ Size SizeMapper::DoMapFromString(String str) { } else if (values.size() == 1) { return {values[0], values[0]}; } else { - throw Exception(u"Invalid Point string."); + throw Exception("Invalid Point string."); } } diff --git a/src/ui/mapper/ThicknessMapper.cpp b/src/ui/mapper/ThicknessMapper.cpp index 23be89b4..eed7c651 100644 --- a/src/ui/mapper/ThicknessMapper.cpp +++ b/src/ui/mapper/ThicknessMapper.cpp @@ -15,7 +15,7 @@ Thickness ThicknessMapper::DoMapFromString(String str) { } else if (values.size() == 1) { return Thickness(values[0], values[0], values[0], values[0]); } else { - throw Exception(u"Invalid Thickness string."); + throw Exception("Invalid Thickness string."); } } diff --git a/src/ui/mapper/style/CheckedConditionMapper.cpp b/src/ui/mapper/style/CheckedConditionMapper.cpp index 74e0a3c5..e33c1113 100644 --- a/src/ui/mapper/style/CheckedConditionMapper.cpp +++ b/src/ui/mapper/style/CheckedConditionMapper.cpp @@ -16,7 +16,7 @@ ClonablePtr<ui::style::CheckedCondition> CheckedConditionMapper::DoMapFromXml( } else if (value.CaseInsensitiveEqual(u"false")) { return ui::style::CheckedCondition::Create(false); } else { - throw Exception(u"Invalid value for CheckedCondition: " + value); + throw Exception("Invalid value for CheckedCondition: " + value.ToUtf8()); } } } // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/ClickStateConditionMapper.cpp b/src/ui/mapper/style/ClickStateConditionMapper.cpp index d6b403c9..ca1f09c6 100644 --- a/src/ui/mapper/style/ClickStateConditionMapper.cpp +++ b/src/ui/mapper/style/ClickStateConditionMapper.cpp @@ -24,7 +24,7 @@ ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode *node) { } else if (value_attr->CaseInsensitiveEqual(u"pressinactive")) { state = helper::ClickState::PressInactive; } else { - throw Exception(u"Unknown click state: " + *value_attr); + throw Exception("Unknown click state: " + value_attr->ToUtf8()); } } diff --git a/src/ui/mapper/style/FocusConditionMapper.cpp b/src/ui/mapper/style/FocusConditionMapper.cpp index dfefb921..9aa1d6ce 100644 --- a/src/ui/mapper/style/FocusConditionMapper.cpp +++ b/src/ui/mapper/style/FocusConditionMapper.cpp @@ -1,5 +1,5 @@ -#include "cru/base/ClonablePtr.h" #include "cru/ui/mapper/style/FocusConditionMapper.h" +#include "cru/base/ClonablePtr.h" #include "cru/ui/style/Condition.h" #include "cru/xml/XmlNode.h" @@ -16,7 +16,7 @@ ClonablePtr<ui::style::FocusCondition> FocusConditionMapper::DoMapFromXml( } else if (value.CaseInsensitiveEqual(u"false")) { return ui::style::FocusCondition::Create(false); } else { - throw Exception(u"Invalid value for FocusCondition: " + value); + throw Exception("Invalid value for FocusCondition: " + value.ToUtf8()); } } } // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/HoverConditionMapper.cpp b/src/ui/mapper/style/HoverConditionMapper.cpp index 0110edd9..27565192 100644 --- a/src/ui/mapper/style/HoverConditionMapper.cpp +++ b/src/ui/mapper/style/HoverConditionMapper.cpp @@ -17,7 +17,7 @@ ClonablePtr<HoverCondition> HoverConditionMapper::DoMapFromXml( } else if (value.CaseInsensitiveEqual(u"false")) { return ui::style::HoverCondition::Create(false); } else { - throw Exception(u"Invalid value for HoverCondition: " + value); + throw Exception("Invalid value for HoverCondition: " + value.ToUtf8()); } } } // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/StyleRuleMapper.cpp b/src/ui/mapper/style/StyleRuleMapper.cpp index 2eb5b0a2..f80d27db 100644 --- a/src/ui/mapper/style/StyleRuleMapper.cpp +++ b/src/ui/mapper/style/StyleRuleMapper.cpp @@ -49,7 +49,7 @@ ClonablePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml( } if (!resolved) { - throw Exception(u"Unknown element in StyleRule: " + c->GetTag()); + throw Exception("Unknown element in StyleRule: " + c->GetTag().ToUtf8()); } } } diff --git a/src/ui/mapper/style/StyleRuleSetMapper.cpp b/src/ui/mapper/style/StyleRuleSetMapper.cpp index d014edc7..1067f8f8 100644 --- a/src/ui/mapper/style/StyleRuleSetMapper.cpp +++ b/src/ui/mapper/style/StyleRuleSetMapper.cpp @@ -25,7 +25,7 @@ std::shared_ptr<ui::style::StyleRuleSet> StyleRuleSetMapper::DoMapFromXml( auto style_rule = style_rule_mapper->MapFromXml(c); result->AddStyleRule(*style_rule); } else { - throw Exception(u"StyleRuleSet can only contain StyleRule."); + throw Exception("StyleRuleSet can only contain StyleRule."); } } } diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index 1803a131..521e88c2 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -239,7 +239,7 @@ void RenderObject::OnLayoutCore() { } Size RenderObject::OnMeasureContent1(const BoxConstraint& constraint) { - throw Exception(u"Not implemented."); + throw Exception("Not implemented."); } Rect RenderObject::GetPaddingRect() const { diff --git a/src/ui/style/StyleRuleSet.cpp b/src/ui/style/StyleRuleSet.cpp index 5468949a..b7a82577 100644 --- a/src/ui/style/StyleRuleSet.cpp +++ b/src/ui/style/StyleRuleSet.cpp @@ -27,7 +27,7 @@ StyleRuleSet::StyleRuleSet(std::shared_ptr<StyleRuleSet> parent) { void StyleRuleSet::SetParent(std::shared_ptr<StyleRuleSet> parent) { if (parent == parent_) return; if (CheckCycle(this, parent.get())) { - throw Exception(u"Cycle detected in StyleRuleSet parent."); + throw Exception("Cycle detected in StyleRuleSet parent."); } parent_change_event_guard_.Reset(); parent_ = std::move(parent); diff --git a/src/xml/XmlParser.cpp b/src/xml/XmlParser.cpp index 313015d5..9256dac7 100644 --- a/src/xml/XmlParser.cpp +++ b/src/xml/XmlParser.cpp @@ -15,7 +15,7 @@ XmlElementNode* XmlParser::Parse() { char16_t XmlParser::Read1() { if (current_position_ >= xml_.size()) { - throw XmlParsingException(u"Unexpected end of xml"); + throw XmlParsingException("Unexpected end of xml"); } return xml_[current_position_++]; } @@ -61,7 +61,7 @@ String XmlParser::ReadIdenitifier() { String XmlParser::ReadAttributeString() { if (Read1() != '"') { - throw XmlParsingException(u"Expected \"."); + throw XmlParsingException("Expected \"."); } String string; @@ -98,13 +98,13 @@ XmlElementNode* XmlParser::DoParse() { String tag = ReadIdenitifier(); if (tag != current_->GetTag()) { - throw XmlParsingException(u"Tag mismatch."); + throw XmlParsingException("Tag mismatch."); } ReadSpacesAndDiscard(); if (Read1() != '>') { - throw XmlParsingException(u"Expected >."); + throw XmlParsingException("Expected >."); } current_ = current_->GetParent(); @@ -115,7 +115,7 @@ XmlElementNode* XmlParser::DoParse() { while (true) { auto str = ReadWithoutAdvance(3); if (str == u"-->") break; - if (str.empty()) throw XmlParsingException(u"Unexpected end of xml"); + if (str.empty()) throw XmlParsingException("Unexpected end of xml"); text += Read1(); } @@ -140,7 +140,7 @@ XmlElementNode* XmlParser::DoParse() { current_position_ += 1; if (Read1() != '>') { - throw XmlParsingException(u"Expected >."); + throw XmlParsingException("Expected >."); } is_self_closing = true; @@ -151,7 +151,7 @@ XmlElementNode* XmlParser::DoParse() { ReadSpacesAndDiscard(); if (Read1() != '=') { - throw XmlParsingException(u"Expected '='"); + throw XmlParsingException("Expected '='"); } ReadSpacesAndDiscard(); @@ -183,11 +183,11 @@ XmlElementNode* XmlParser::DoParse() { } if (current_ != pseudo_root_node_) { - throw XmlParsingException(u"Unexpected end of xml"); + throw XmlParsingException("Unexpected end of xml"); } if (pseudo_root_node_->GetChildren().size() != 1) { - throw XmlParsingException(u"Expected 1 node as root."); + throw XmlParsingException("Expected 1 node as root."); } return static_cast<XmlElementNode*>(pseudo_root_node_->GetChildren()[0]); |