diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 14:33:16 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 14:33:16 +0800 |
commit | 9f419314b646bf57dfc3fcbb509b3be2c974e3fd (patch) | |
tree | 6d40efce7beade635b6480a9b4e7db2f114c2145 /src | |
parent | 5c5c496b605886b286d1b99e0f9e28ec02117ad5 (diff) | |
download | cru-9f419314b646bf57dfc3fcbb509b3be2c974e3fd.tar.gz cru-9f419314b646bf57dfc3fcbb509b3be2c974e3fd.tar.bz2 cru-9f419314b646bf57dfc3fcbb509b3be2c974e3fd.zip |
Remove String on Linux.
Diffstat (limited to 'src')
-rw-r--r-- | src/ThemeBuilder/components/StyleRuleSetEditor.cpp | 1 | ||||
-rw-r--r-- | src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp | 1 | ||||
-rw-r--r-- | src/base/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/base/Format.cpp | 111 | ||||
-rw-r--r-- | src/base/String.cpp | 565 | ||||
-rw-r--r-- | src/platform/graphics/direct2d/Font.cpp | 1 | ||||
-rw-r--r-- | src/ui/ThemeManager.cpp | 4 | ||||
-rw-r--r-- | src/ui/ThemeResourceDictionary.cpp | 4 | ||||
-rw-r--r-- | src/ui/document/DocumentElementType.cpp | 8 | ||||
-rw-r--r-- | src/ui/document/TextDocumentElement.cpp | 5 | ||||
-rw-r--r-- | src/ui/host/RoutedEventDispatch.h | 10 | ||||
-rw-r--r-- | src/ui/host/WindowHost.cpp | 3 | ||||
-rw-r--r-- | src/ui/mapper/FontMapper.cpp | 1 | ||||
-rw-r--r-- | src/ui/mapper/StringMapper.cpp | 9 | ||||
-rw-r--r-- | src/ui/render/BorderRenderObject.cpp | 2 | ||||
-rw-r--r-- | src/ui/render/FlexLayoutRenderObject.cpp | 5 | ||||
-rw-r--r-- | src/ui/render/RenderObject.cpp | 27 | ||||
-rw-r--r-- | src/ui/style/StyleRule.cpp | 2 |
18 files changed, 38 insertions, 723 deletions
diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp index ccffa591..a4e15fe7 100644 --- a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp +++ b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp @@ -1,6 +1,5 @@ #include "StyleRuleSetEditor.h" #include "cru/base/Exception.h" -#include "cru/base/String.h" #include "cru/ui/DeleteLater.h" #include "cru/ui/ThemeManager.h" #include "cru/ui/controls/FlexLayout.h" diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp index 2ee13c06..bd8c64b9 100644 --- a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp @@ -1,6 +1,5 @@ #include "ThicknessPropertyEditor.h" #include <format> -#include "cru/base/Format.h" #include "cru/ui/mapper/MapperRegistry.h" #include "cru/ui/mapper/ThicknessMapper.h" diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 685ceb8c..106a03ef 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -2,9 +2,7 @@ add_library(CruBase Base.cpp Buffer.cpp Exception.cpp - Format.cpp PropertyTree.cpp - String.cpp StringUtil.cpp SubProcess.cpp io/AutoReadStream.cpp diff --git a/src/base/Format.cpp b/src/base/Format.cpp deleted file mode 100644 index e442e572..00000000 --- a/src/base/Format.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "cru/base/Format.h" - -namespace cru { -namespace details { -FormatToken ParsePlaceHolder(String place_holder_string) { - if (place_holder_string.empty()) { - return FormatToken::NonePlaceHolder({}); - } - - if (place_holder_string.StartWith(u":")) { - if (place_holder_string.Find(u':', 1) != -1) { - throw Exception("Two ':' inside placeholder."); - } - - return FormatToken::NonePlaceHolder(place_holder_string.substr(1)); - } - if (IsDigit(place_holder_string[0])) { - int position = 0; - int index = 0; - while (index < place_holder_string.size() && - IsDigit(place_holder_string[index])) { - position = position * 10 + place_holder_string[index] - '0'; - index++; - } - - String option; - - if (index != place_holder_string.size()) { - if (place_holder_string[index] != ':') { - throw Exception("Invalid placeholder in format."); - } - - option = place_holder_string.substr(index + 1); - } - - return FormatToken::PositionedPlaceHolder(position, std::move(option)); - } - - auto separator_index = place_holder_string.Find(':'); - if (separator_index == -1) { - return FormatToken::NamedPlaceHolder(place_holder_string, {}); - } else { - return FormatToken::NamedPlaceHolder( - place_holder_string.substr(0, separator_index), - place_holder_string.substr(separator_index + 1)); - } -} - -std::vector<FormatToken> ParseToFormatTokenList(StringView str) { - std::vector<FormatToken> result; - - auto push_char = [&result](char16_t c) { - if (result.empty() || result.back().type == FormatTokenType::PlaceHolder) { - result.push_back(FormatToken::Text()); - } - result.back().data.append(c); - }; - - bool try_to_escape = false; - bool is_in_place_holder = false; - String place_holder_string; - - for (auto c : str) { - if (c == u'{') { - if (try_to_escape) { - push_char(u'{'); - try_to_escape = false; - is_in_place_holder = false; - } else { - if (is_in_place_holder) { - throw Exception("Invalid format string: '{' inside placeholder."); - } - - try_to_escape = true; - is_in_place_holder = true; - } - } else if (c == u'}') { - if (is_in_place_holder) { - is_in_place_holder = false; - result.push_back(ParsePlaceHolder(std::move(place_holder_string))); - place_holder_string.clear(); - } else { - push_char(u'}'); - } - try_to_escape = false; - } else { - if (is_in_place_holder) { - place_holder_string.push_back(c); - } else { - push_char(c); - } - try_to_escape = false; - } - } - return result; -} - -void FormatAppendFromFormatTokenList( - String& current, const std::vector<FormatToken>& format_token_list, - Index index) { - 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("More placeholder than args."); - } else { - current += token.data; - } - } -} -} // namespace details -} // namespace cru diff --git a/src/base/String.cpp b/src/base/String.cpp deleted file mode 100644 index c96b898d..00000000 --- a/src/base/String.cpp +++ /dev/null @@ -1,565 +0,0 @@ -#include "cru/base/String.h" - -#include "cru/base/Buffer.h" -#include "cru/base/Exception.h" -#include "cru/base/StringUtil.h" - -#include <algorithm> -#include <cstring> -#include <functional> - -#ifdef CRU_PLATFORM_OSX -#include <CoreFoundation/CoreFoundation.h> -#endif - -namespace cru { -template <typename C> -Index GetStrSize(const C* str) { - Index i = 0; - while (str[i]) { - i++; - } - return i; -} - -String String::FromUtf8(const char* str) { - return FromUtf8(str, GetStrSize(str)); -} - -String String::FromUtf8(const char* str, Index size) { - String result; - Utf8CodePointIterator iter(str, size); - for (auto cp : iter) { - Utf16EncodeCodePointAppend( - cp, - std::bind(&String::push_back, std::ref(result), std::placeholders::_1)); - } - return result; -} - -String String::FromUtf8(const std::byte* str, Index size) { - return String::FromUtf8(reinterpret_cast<const char*>(str), size); -} - -String String::FromUtf8(const Buffer& buffer) { - return String::FromUtf8(buffer.GetUsedBeginPtr(), buffer.GetUsedSize()); -} - -String String::FromStdPath(const std::filesystem::path& path) { - return String::FromUtf8(path.string()); -} - -namespace { -char16_t kEmptyBuffer[1] = {0}; -} - -String::String() - : buffer_(kEmptyBuffer), - size_(0), capacity_(0) {} - -String::String(const_pointer str) : String(str, GetStrSize(str)) {} - -String::String(const_pointer str, Index size) { - this->buffer_ = new value_type[size + 1]; - std::memcpy(this->buffer_, str, size * sizeof(char16_t)); - this->buffer_[size] = 0; - this->size_ = size; - this->capacity_ = size; -} - -String::String(size_type size, value_type ch) : String() { - reserve(size); - for (Index i = 0; i < size; i++) { - append(ch); - } -} - -String::String(std::initializer_list<char16_t> l) - : String(l.begin(), l.size()) {} - -#ifdef CRU_PLATFORM_WINDOWS -String::String(const wchar_t* str) : String(str, GetStrSize(str)) {} -String::String(const wchar_t* str, Index size) - : String(reinterpret_cast<const char16_t*>(str), size) {} -#endif - -String::String(const String& other) { - if (other.size_ == 0) { - this->buffer_ = kEmptyBuffer; - this->size_ = this->capacity_ = 0; - return; - } - this->buffer_ = new value_type[other.size_ + 1]; - std::memcpy(this->buffer_, other.buffer_, other.size_ * sizeof(value_type)); - this->buffer_[other.size_] = 0; - this->size_ = other.size_; - this->capacity_ = other.size_; -} - -String::String(String&& other) noexcept { - this->buffer_ = other.buffer_; - this->size_ = other.size_; - this->capacity_ = other.capacity_; - other.buffer_ = kEmptyBuffer; - other.size_ = 0; - other.capacity_ = 0; -} - -String& String::operator=(const String& other) { - if (this != &other) { - if (this->buffer_ != kEmptyBuffer) { - delete[] this->buffer_; - } - - if (other.buffer_ == kEmptyBuffer) { - this->buffer_ = kEmptyBuffer; - this->size_ = 0; - this->capacity_ = 0; - } else { - this->buffer_ = new value_type[other.size_ + 1]; - std::memcpy(this->buffer_, other.buffer_, - other.size_ * sizeof(value_type)); - this->buffer_[other.size_] = 0; - this->size_ = other.size_; - this->capacity_ = other.size_; - } - } - return *this; -} - -String& String::operator=(String&& other) noexcept { - if (this != &other) { - if (this->buffer_ != kEmptyBuffer) { - delete[] this->buffer_; - } - - this->buffer_ = other.buffer_; - this->size_ = other.size_; - this->capacity_ = other.capacity_; - other.buffer_ = kEmptyBuffer; - other.size_ = 0; - other.capacity_ = 0; - } - return *this; -} - -String::~String() { - if (this->buffer_ != kEmptyBuffer) { - delete[] this->buffer_; - } -} - -String::String(from_buffer_tag, pointer buffer, Index size, Index capacity) - : buffer_(buffer), size_(size), capacity_(capacity) {} - -void String::clear() { resize(0); } - -void String::resize(Index new_size) { - Expects(new_size >= 0); - - if (new_size == size_) return; - - if (new_size < size_) { - size_ = new_size; - buffer_[size_] = 0; - } else { - reserve(new_size); - std::memset(buffer_ + size_, 0, sizeof(value_type) * (new_size - size_)); - buffer_[new_size] = 0; - size_ = new_size; - } -} - -void String::shrink_to_fit() { - if (capacity_ == size_) return; - if (size_ == 0) { - delete[] buffer_; - buffer_ = kEmptyBuffer; - size_ = 0; - capacity_ = 0; - } else { - auto new_buffer = new value_type[size_ + 1]; - std::memcpy(new_buffer, buffer_, sizeof(value_type) * size_); - delete[] buffer_; - buffer_ = new_buffer; - capacity_ = size_; - } -} - -void String::reserve(Index new_capacity) { - Expects(new_capacity >= 0); - if (new_capacity <= this->capacity_) return; - if (new_capacity > 0) { - pointer new_buffer = new value_type[new_capacity + 1]; - if (this->buffer_ != kEmptyBuffer) { - memcpy(new_buffer, this->buffer_, this->size_ * sizeof(value_type)); - delete[] this->buffer_; - } - new_buffer[this->size_] = 0; - this->buffer_ = new_buffer; - this->capacity_ = new_capacity; - } -} - -String::iterator String::insert(const_iterator pos, const_iterator str, - Index size) { - Expects(pos >= cbegin() && pos <= cend()); - - std::vector<value_type> backup_buffer; - if (str >= buffer_ && str < buffer_ + size_) { - backup_buffer.resize(size); - std::copy(str, str + size, backup_buffer.begin()); - str = backup_buffer.data(); - } - - Index index = pos - cbegin(); - - Index new_size = size_ + size; - if (new_size > capacity_) { - auto new_capacity = capacity_; - if (new_capacity == 0) { - new_capacity = new_size; - } else { - while (new_capacity < new_size) { - new_capacity *= 2; - } - } - - this->reserve(new_capacity); - } - - std::memmove(begin() + index + size, begin() + index, - (size_ - index) * sizeof(value_type)); - std::memcpy(begin() + index, str, size * sizeof(value_type)); - - buffer_[new_size] = 0; - size_ = new_size; - - return begin() + new_size; -} - -String::iterator String::erase(const_iterator start, const_iterator end) { - Expects(buffer_ <= start && start <= end && end <= buffer_ + size_); - - Index new_size = size_ - (end - start); - - auto s = const_cast<iterator>(start); - auto e = const_cast<iterator>(end); - - std::memmove(s, e, (cend() - end) * sizeof(value_type)); - this->size_ = new_size; - this->buffer_[new_size] = 0; - - return s; -} - -String& String::operator+=(StringView other) { - append(other); - return *this; -} - -StringView String::View() const { return *this; } - -Index String::Find(value_type value, Index start) const { - return View().Find(value, start); -} - -std::vector<String> String::Split(value_type separator, - bool remove_space_line) const { - return View().Split(separator, remove_space_line); -} - -std::vector<String> String::SplitToLines(bool remove_space_line) const { - return View().SplitToLines(remove_space_line); -} - -bool String::StartWith(StringView str) const { return View().StartWith(str); } - -bool String::EndWith(StringView str) const { return View().EndWith(str); } - -std::string String::ToUtf8() const { return View().ToUtf8(); } - -Buffer String::ToUtf8Buffer(bool end_zero) const { - return View().ToUtf8Buffer(); -} - -String& String::TrimStart() { - if (size_ == 0) return *this; - - auto start = begin(); - while (start != end() && IsWhitespace(*start)) { - ++start; - } - - if (start == end()) { - clear(); - } else { - erase(begin(), start); - } - - return *this; -} - -String& String::TrimEnd() { - if (size_ == 0) return *this; - while (size_ > 0 && IsWhitespace(buffer_[size_ - 1])) { - size_--; - } - - return *this; -} - -String& String::Trim() { - TrimStart(); - TrimEnd(); - return *this; -} - -void String::AppendCodePoint(CodePoint code_point) { - if (!Utf16EncodeCodePointAppend( - code_point, - std::bind(&String::push_back, this, std::placeholders::_1))) { - throw TextEncodeException("Code point out of range."); - } -} - -Index String::IndexFromCodeUnitToCodePoint(Index code_unit_index) const { - return View().IndexFromCodeUnitToCodePoint(code_unit_index); -} - -Index String::IndexFromCodePointToCodeUnit(Index code_point_index) const { - return View().IndexFromCodePointToCodeUnit(code_point_index); -} - -Range String::RangeFromCodeUnitToCodePoint(Range code_unit_range) const { - return View().RangeFromCodeUnitToCodePoint(code_unit_range); -} - -Range String::RangeFromCodePointToCodeUnit(Range code_point_range) const { - return View().RangeFromCodePointToCodeUnit(code_point_range); -} - -std::ostream& operator<<(std::ostream& os, const String& value) { - os << value.ToUtf8(); - return os; -} - -namespace { -inline int Compare(char16_t left, char16_t right) { - if (left < right) return -1; - if (left > right) return 1; - return 0; -} - -inline int CaseInsensitiveCompare(char16_t left, char16_t right) { - return Compare(ToLower(left), ToLower(right)); -} -} // namespace - -int String::Compare(const String& other) const { return View().Compare(other); } -int String::CaseInsensitiveCompare(const String& other) const { - return View().CaseInsensitiveCompare(other); -} - -int StringView::Compare(const StringView& other) const { - const_iterator i1 = cbegin(); - const_iterator i2 = other.cbegin(); - - const_iterator end1 = cend(); - const_iterator end2 = other.cend(); - - while (i1 != end1 && i2 != end2) { - int r = cru::Compare(*i1, *i2); - if (r != 0) return r; - i1++; - i2++; - } - - if (i1 == end1) { - if (i2 == end2) { - return 0; - } else { - return -1; - } - } else { - return 1; - } -} - -int StringView::CaseInsensitiveCompare(const StringView& other) const { - const_iterator i1 = cbegin(); - const_iterator i2 = other.cbegin(); - - const_iterator end1 = cend(); - const_iterator end2 = other.cend(); - - while (i1 != end1 && i2 != end2) { - int r = cru::CaseInsensitiveCompare(*i1, *i2); - if (r != 0) return r; - i1++; - i2++; - } - - if (i1 == end1) { - if (i2 == end2) { - return 0; - } else { - return -1; - } - } else { - return 1; - } -} - -StringView StringView::substr(Index pos) { - Expects(pos >= 0 && pos < size_); - return StringView(ptr_ + pos, size_ - pos); -} - -StringView StringView::substr(Index pos, Index size) { - Expects(pos >= 0 && pos < size_); - - return StringView(ptr_ + pos, std::min(size, size_ - pos)); -} - -Index StringView::Find(value_type value, Index start) const { - Expects(start >= 0 && start <= size_); - - for (Index i = start; i < size_; ++i) { - if (ptr_[i] == value) return i; - } - return -1; -} - -std::vector<String> StringView::Split(value_type separator, - bool remove_space_line) const { - std::vector<String> result; - - if (size_ == 0) return result; - - Index line_start = 0; - Index line_end = 0; - while (line_end < size_) { - if (ptr_[line_end] == separator) { - if (remove_space_line) { - bool add = false; - for (Index i = line_start; i < line_end; i++) { - if (!IsWhitespace(ptr_[i])) { - add = true; - break; - } - } - if (add) result.emplace_back(begin() + line_start, begin() + line_end); - } else { - result.emplace_back(begin() + line_start, begin() + line_end); - } - line_start = line_end + 1; - line_end = line_start; - } else { - line_end++; - } - } - - if (remove_space_line) { - bool add = false; - for (Index i = line_start; i < size_; i++) { - if (!IsWhitespace(ptr_[i])) { - add = true; - break; - } - } - if (add) result.emplace_back(begin() + line_start, begin() + size_); - } else { - result.emplace_back(begin() + line_start, begin() + size_); - } - - return result; -} - -std::vector<String> StringView::SplitToLines(bool remove_space_line) const { - return Split(u'\n', remove_space_line); -} - -bool StringView::StartWith(StringView str) const { - if (str.size() > size_) return false; - return std::memcmp(str.data(), ptr_, str.size()) == 0; -} - -bool StringView::EndWith(StringView str) const { - if (str.size() > size_) return false; - return std::memcmp(str.data(), ptr_ + size_ - str.size(), str.size()) == 0; -} - -Index StringView::IndexFromCodeUnitToCodePoint(Index code_unit_index) const { - auto iter = CodePointIterator(); - Index result = 0; - while (iter.GetPosition() < code_unit_index && !iter.IsPastEnd()) { - ++iter; - ++result; - } - return result; -} - -Index StringView::IndexFromCodePointToCodeUnit(Index code_point_index) const { - auto iter = CodePointIterator(); - Index cpi = 0; - while (cpi < code_point_index && !iter.IsPastEnd()) { - ++iter; - ++cpi; - } - return iter.GetPosition(); -} - -Range StringView::RangeFromCodeUnitToCodePoint(Range code_unit_range) const { - return Range::FromTwoSides( - IndexFromCodeUnitToCodePoint(code_unit_range.GetStart()), - IndexFromCodeUnitToCodePoint(code_unit_range.GetEnd())); -} - -Range StringView::RangeFromCodePointToCodeUnit(Range code_point_range) const { - return Range::FromTwoSides( - IndexFromCodePointToCodeUnit(code_point_range.GetStart()), - IndexFromCodePointToCodeUnit(code_point_range.GetEnd())); -} - -std::string StringView::ToUtf8() const { - std::string result; - for (auto cp : CodePointIterator()) { - Utf8EncodeCodePointAppend( - cp, std::bind(&std::string::push_back, std::ref(result), - std::placeholders::_1)); - } - return result; -} - -Buffer StringView::ToUtf8Buffer(bool end_zero) const { - const Index grow_step = 10; - Buffer buffer(grow_step); // Maybe another init value is more reasonable. - auto push_back = [&buffer](char c) { - if (buffer.IsUsedReachEnd()) { - buffer.ResizeBuffer(buffer.GetBufferSize() + grow_step, true); - } - buffer.PushBack(static_cast<std::byte>(c)); - }; - for (auto cp : CodePointIterator()) { - Utf8EncodeCodePointAppend(cp, push_back); - } - if (end_zero) { - push_back(0); - } - return buffer; -} - -String ToLower(StringView s) { - String result; - for (auto c : s) result.push_back(ToLower(c)); - return result; -} - -String ToUpper(StringView s) { - String result; - for (auto c : s) result.push_back(ToUpper(c)); - return result; -} - -} // namespace cru diff --git a/src/platform/graphics/direct2d/Font.cpp b/src/platform/graphics/direct2d/Font.cpp index b1c03751..34bb2ea5 100644 --- a/src/platform/graphics/direct2d/Font.cpp +++ b/src/platform/graphics/direct2d/Font.cpp @@ -1,6 +1,5 @@ #include "cru/platform/graphics/direct2d/Font.h" -#include "cru/base/Format.h" #include "cru/platform/graphics/direct2d/Exception.h" #include "cru/platform/graphics/direct2d/Factory.h" diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index 0f4daeb7..14da3ef8 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -20,7 +20,7 @@ ThemeManager::ThemeManager() { } PrependThemeResourceDictionary( - ThemeResourceDictionary::FromFile(String::FromStdPath(resourses_file))); + ThemeResourceDictionary::FromFile(resourses_file)); } ThemeManager::~ThemeManager() {} @@ -44,7 +44,7 @@ void ThemeManager::PrependThemeResourceDictionary( } std::string ThemeManager::GetResourceString(std::string_view key) { - return GetResource<String>(key).ToUtf8(); + return GetResource<std::string>(key); } std::shared_ptr<platform::graphics::IBrush> ThemeManager::GetResourceBrush( diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp index f76bdde8..587a14c5 100644 --- a/src/ui/ThemeResourceDictionary.cpp +++ b/src/ui/ThemeResourceDictionary.cpp @@ -8,8 +8,8 @@ namespace cru::ui { std::unique_ptr<ThemeResourceDictionary> ThemeResourceDictionary::FromFile( - const String& file_path) { - io::CFileStream stream(file_path.ToUtf8().c_str(), "r"); + std::filesystem::path file_path) { + io::CFileStream stream(file_path.c_str(), "r"); auto xml_string = stream.ReadToEndAsUtf8String(); auto parser = xml::XmlParser(xml_string); return std::make_unique<ThemeResourceDictionary>(parser.Parse(), false); diff --git a/src/ui/document/DocumentElementType.cpp b/src/ui/document/DocumentElementType.cpp index d548b494..ed076169 100644 --- a/src/ui/document/DocumentElementType.cpp +++ b/src/ui/document/DocumentElementType.cpp @@ -5,17 +5,17 @@ namespace cru::ui::document { DocumentElementType::DocumentElementType( - String name, std::vector<DocumentElementType*> parents) + std::string name, std::vector<DocumentElementType*> parents) : name_(std::move(name)), parents_(std::move(parents)) {} DocumentElementType::~DocumentElementType() {} DocumentElementType* const DocumentElementTypes::kBaseElementType = - new DocumentElementType(u"Base", {}); + new DocumentElementType("Base", {}); DocumentElementType* const DocumentElementTypes::kRootElementType = - new DocumentElementType(u"Root", {kBaseElementType}); + new DocumentElementType("Root", {kBaseElementType}); DocumentElementType* const DocumentElementTypes::kTextElementType = - new DocumentElementType(u"Text", {kBaseElementType}); + new DocumentElementType("Text", {kBaseElementType}); } // namespace cru::ui::document diff --git a/src/ui/document/TextDocumentElement.cpp b/src/ui/document/TextDocumentElement.cpp index 1ba39849..52cfac5a 100644 --- a/src/ui/document/TextDocumentElement.cpp +++ b/src/ui/document/TextDocumentElement.cpp @@ -1,10 +1,9 @@ #include "cru/ui/document/TextDocumentElement.h" -#include "cru/base/String.h" #include "cru/ui/document/DocumentElement.h" #include "cru/ui/document/DocumentElementType.h" namespace cru::ui::document { -TextDocumentElement::TextDocumentElement(String text, TextStyle style, +TextDocumentElement::TextDocumentElement(std::string text, TextStyle style, IDocumentLink* link) : DocumentElement(DocumentElementTypes::kTextElementType), text_(std::move(text)), @@ -13,5 +12,5 @@ TextDocumentElement::TextDocumentElement(String text, TextStyle style, TextDocumentElement::~TextDocumentElement() {} -void TextDocumentElement::SetText(String text) { text_ = std::move(text); } +void TextDocumentElement::SetText(std::string text) { text_ = std::move(text); } } // namespace cru::ui::document diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h index 98042841..0729d176 100644 --- a/src/ui/host/RoutedEventDispatch.h +++ b/src/ui/host/RoutedEventDispatch.h @@ -23,7 +23,7 @@ namespace cru::ui::host { // as the rest arguments. template <typename EventArgs, typename... Args> void DispatchEvent( - const String& event_name, controls::Control* const original_sender, + const std::string& event_name, controls::Control* const original_sender, events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(), controls::Control* const last_receiver, Args&&... args) { constexpr auto kLogTag = "DispatchEvent"; @@ -37,7 +37,7 @@ void DispatchEvent( CRU_LOG_TAG_DEBUG( "Routed event {} no need to dispatch (original_sender == " "last_receiver). Original sender is {}.", - event_name.ToUtf8(), original_sender->GetControlType().ToUtf8()); + event_name, original_sender->GetControlType()); return; } @@ -55,15 +55,15 @@ void DispatchEvent( if constexpr (debug_flags::routed_event) { std::string log = "Dispatch routed event "; - log += event_name.ToUtf8(); + log += event_name; log += ". Path (parent first): "; auto i = receive_list.crbegin(); const auto end = --receive_list.crend(); for (; i != end; ++i) { - log += i->Resolve()->GetControlType().ToUtf8(); + log += i->Resolve()->GetControlType(); log += " -> "; } - log += i->Resolve()->GetControlType().ToUtf8(); + log += i->Resolve()->GetControlType(); CRU_LOG_TAG_DEBUG("{}", log); } diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 88e8cc87..4c707772 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -21,8 +21,7 @@ using platform::gui::INativeWindow; using platform::gui::IUiApplication; namespace event_names { -#define CRU_DEFINE_EVENT_NAME(name) \ - constexpr const char16_t* name = CRU_MAKE_UNICODE_LITERAL(name); +#define CRU_DEFINE_EVENT_NAME(name) constexpr const char* name = #name; CRU_DEFINE_EVENT_NAME(LoseFocus) CRU_DEFINE_EVENT_NAME(GainFocus) diff --git a/src/ui/mapper/FontMapper.cpp b/src/ui/mapper/FontMapper.cpp index a0dcdd9f..ebf7c27c 100644 --- a/src/ui/mapper/FontMapper.cpp +++ b/src/ui/mapper/FontMapper.cpp @@ -1,6 +1,5 @@ #include "cru/ui/mapper/FontMapper.h" #include "../Helper.h" -#include "cru/base/String.h" #include "cru/base/StringUtil.h" #include "cru/platform/graphics/Factory.h" diff --git a/src/ui/mapper/StringMapper.cpp b/src/ui/mapper/StringMapper.cpp index 5914da17..6f6b4546 100644 --- a/src/ui/mapper/StringMapper.cpp +++ b/src/ui/mapper/StringMapper.cpp @@ -1,19 +1,18 @@ #include "cru/ui/mapper/StringMapper.h" #include "cru/xml/XmlNode.h" -#include "cru/base/String.h" namespace cru::ui::mapper { StringMapper::StringMapper() { SetAllowedTags({"String"}); } StringMapper::~StringMapper() {} -String StringMapper::DoMapFromString(std::string str) { - return String::FromUtf8(str); +std::string StringMapper::DoMapFromString(std::string str) { + return std::move(str); } -String StringMapper::DoMapFromXml(xml::XmlElementNode* node) { +std::string StringMapper::DoMapFromXml(xml::XmlElementNode* node) { auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value"); - if (value_attr) return String::FromUtf8(*value_attr); + if (value_attr) return *value_attr; return {}; } } // namespace cru::ui::mapper diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 957cf9bb..5c4bc22c 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -244,5 +244,5 @@ void BorderRenderObject::RecreateGeometry() { builder.reset(); } -String BorderRenderObject::GetName() const { return u"BorderRenderObject"; } +std::string BorderRenderObject::GetName() const { return "BorderRenderObject"; } } // namespace cru::ui::render diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index efc98602..53193867 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -4,12 +4,11 @@ #include "cru/ui/render/LayoutHelper.h" #include <algorithm> -#include <functional> #include <type_traits> namespace cru::ui::render { -String FlexLayoutRenderObject::GetName() const { - return u"FlexLayoutRenderObject"; +std::string FlexLayoutRenderObject::GetName() const { + return "FlexLayoutRenderObject"; } struct tag_horizontal_t {}; diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index 521e88c2..d10fd897 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -119,16 +119,17 @@ void RenderObject::Measure(const MeasureRequirement& requirement, preferred_size.OverrideBy(preferred_size_); if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG("{} Measure begins :\nrequirement: {}\npreferred size: {}", - this->GetDebugPathInTree().ToUtf8(), requirement.ToDebugString().ToUtf8(), - preferred_size.ToDebugString().ToUtf8()); + CRU_LOG_TAG_DEBUG( + "{} Measure begins :\nrequirement: {}\npreferred size: {}", + this->GetDebugPathInTree(), requirement.ToDebugString(), + preferred_size.ToDebugString()); } desired_size_ = OnMeasureCore(merged_requirement, merged_preferred_size); if constexpr (cru::ui::debug_flags::layout) { CRU_LOG_TAG_DEBUG("{} Measure ends :\nresult size: {}", - this->GetDebugPathInTree().ToUtf8(), desired_size_); + this->GetDebugPathInTree(), desired_size_); } Ensures(desired_size_.width >= 0); @@ -145,7 +146,7 @@ Size RenderObject::Measure1(const BoxConstraint& constraint) { void RenderObject::Layout(const Point& offset) { if constexpr (cru::ui::debug_flags::layout) { CRU_LOG_TAG_DEBUG("{} Layout :\noffset: {} size: {}", - this->GetDebugPathInTree().ToUtf8(), offset, desired_size_); + this->GetDebugPathInTree(), offset, desired_size_); } offset_ = offset; size_ = desired_size_; @@ -193,13 +194,13 @@ Size RenderObject::OnMeasureCore1(const BoxConstraint& constraint) { if (space_size.width > merged_constraint.max.width) { space_size.width = merged_constraint.max.width; CRU_LOG_TAG_WARN("{} space width is over constraint.max.width", - this->GetDebugPathInTree().ToUtf8()); + this->GetDebugPathInTree()); } if (space_size.height > merged_constraint.max.height) { space_size.height = merged_constraint.max.height; CRU_LOG_TAG_WARN("{} space height is over constraint.max.height", - this->GetDebugPathInTree().ToUtf8()); + this->GetDebugPathInTree()); } BoxConstraint content_constraint{merged_constraint.max - space_size, @@ -284,20 +285,20 @@ void RenderObject::InvalidatePaint() { } } -String kUnamedName(u"UNNAMED"); -String RenderObject::GetName() const { return kUnamedName; } +std::string kUnamedName("UNNAMED"); +std::string RenderObject::GetName() const { return kUnamedName; } -String RenderObject::GetDebugPathInTree() const { - std::vector<String> chain; +std::string RenderObject::GetDebugPathInTree() const { + std::vector<std::string> chain; const RenderObject* parent = this; while (parent != nullptr) { chain.push_back(parent->GetName()); parent = parent->GetParent(); } - String result(chain.back()); + std::string result(chain.back()); for (auto iter = chain.crbegin() + 1; iter != chain.crend(); ++iter) { - result += u" -> "; + result += " -> "; result += *iter; } diff --git a/src/ui/style/StyleRule.cpp b/src/ui/style/StyleRule.cpp index ce823537..8b9b0a56 100644 --- a/src/ui/style/StyleRule.cpp +++ b/src/ui/style/StyleRule.cpp @@ -2,7 +2,7 @@ namespace cru::ui::style { StyleRule::StyleRule(ClonablePtr<Condition> condition, - ClonablePtr<Styler> styler, String name) + ClonablePtr<Styler> styler, std::string name) : condition_(std::move(condition)), styler_(std::move(styler)), name_(std::move(name)) {} |