aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/base/Base.h3
-rw-r--r--include/cru/base/Format.h173
-rw-r--r--include/cru/base/String.h442
-rw-r--r--include/cru/base/StringUtil.h8
-rw-r--r--include/cru/ui/ThemeManager.h3
-rw-r--r--include/cru/ui/ThemeResourceDictionary.h6
-rw-r--r--include/cru/ui/controls/Button.h4
-rw-r--r--include/cru/ui/controls/CheckBox.h4
-rw-r--r--include/cru/ui/controls/Container.h4
-rw-r--r--include/cru/ui/controls/Control.h2
-rw-r--r--include/cru/ui/controls/FlexLayout.h4
-rw-r--r--include/cru/ui/controls/IconButton.h4
-rw-r--r--include/cru/ui/controls/Popup.h4
-rw-r--r--include/cru/ui/controls/ScrollView.h4
-rw-r--r--include/cru/ui/controls/StackLayout.h4
-rw-r--r--include/cru/ui/controls/TextBlock.h4
-rw-r--r--include/cru/ui/controls/TextBox.h4
-rw-r--r--include/cru/ui/controls/TreeView.h6
-rw-r--r--include/cru/ui/controls/Window.h5
-rw-r--r--include/cru/ui/document/DocumentElementType.h7
-rw-r--r--include/cru/ui/document/TextDocumentElement.h8
-rw-r--r--include/cru/ui/mapper/StringMapper.h8
-rw-r--r--include/cru/ui/render/BorderRenderObject.h2
-rw-r--r--include/cru/ui/render/FlexLayoutRenderObject.h2
-rw-r--r--include/cru/ui/render/MeasureRequirement.h22
-rw-r--r--include/cru/ui/render/RenderObject.h5
-rw-r--r--include/cru/ui/render/ScrollRenderObject.h2
-rw-r--r--include/cru/ui/render/StackLayoutRenderObject.h2
-rw-r--r--include/cru/ui/render/TextRenderObject.h2
-rw-r--r--include/cru/ui/render/TreeRenderObject.h2
-rw-r--r--include/cru/ui/style/StyleRule.h16
-rw-r--r--src/ThemeBuilder/components/StyleRuleSetEditor.cpp1
-rw-r--r--src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp1
-rw-r--r--src/base/CMakeLists.txt2
-rw-r--r--src/base/Format.cpp111
-rw-r--r--src/base/String.cpp565
-rw-r--r--src/platform/graphics/direct2d/Font.cpp1
-rw-r--r--src/ui/ThemeManager.cpp4
-rw-r--r--src/ui/ThemeResourceDictionary.cpp4
-rw-r--r--src/ui/document/DocumentElementType.cpp8
-rw-r--r--src/ui/document/TextDocumentElement.cpp5
-rw-r--r--src/ui/host/RoutedEventDispatch.h10
-rw-r--r--src/ui/host/WindowHost.cpp3
-rw-r--r--src/ui/mapper/FontMapper.cpp1
-rw-r--r--src/ui/mapper/StringMapper.cpp9
-rw-r--r--src/ui/render/BorderRenderObject.cpp2
-rw-r--r--src/ui/render/FlexLayoutRenderObject.cpp5
-rw-r--r--src/ui/render/RenderObject.cpp27
-rw-r--r--src/ui/style/StyleRule.cpp2
-rw-r--r--test/base/CMakeLists.txt1
-rw-r--r--test/base/StringTest.cpp86
-rw-r--r--test/base/StringUtilTest.cpp1
52 files changed, 104 insertions, 1511 deletions
diff --git a/include/cru/base/Base.h b/include/cru/base/Base.h
index 369dd5c3..28983469 100644
--- a/include/cru/base/Base.h
+++ b/include/cru/base/Base.h
@@ -16,9 +16,6 @@
#define CRU_UNUSED(entity) static_cast<void>(entity);
-#define CRU__CONCAT(a, b) a##b
-#define CRU_MAKE_UNICODE_LITERAL(str) CRU__CONCAT(u, #str)
-
#define CRU_DEFAULT_COPY(classname) \
classname(const classname&) = default; \
classname& operator=(const classname&) = default;
diff --git a/include/cru/base/Format.h b/include/cru/base/Format.h
deleted file mode 100644
index 4f56d189..00000000
--- a/include/cru/base/Format.h
+++ /dev/null
@@ -1,173 +0,0 @@
-#pragma once
-
-#include "Exception.h"
-#include "String.h"
-
-#include <cassert>
-#include <cstdio>
-#include <format>
-#include <type_traits>
-#include <vector>
-
-namespace cru {
-inline String ToString(bool value) {
- return value ? String(u"true") : String(u"false");
-}
-
-template <typename T>
-inline constexpr std::nullptr_t kPrintfFormatSpecifierOfType = nullptr;
-
-#define CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(type, specifier) \
- template <> \
- inline constexpr const char* kPrintfFormatSpecifierOfType<type> = specifier;
-
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(signed char, "%c")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(unsigned char, "%c")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(signed short, "%hd")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(unsigned short, "%hu")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(signed int, "%d")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(unsigned int, "%u")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(signed long, "%ld")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(unsigned long, "%lu")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(signed long long, "%lld")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(unsigned long long, "%llu")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(float, "%f")
-CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE(double, "%f")
-
-#undef CRU_DEFINE_PRINTF_FORMAT_SPECIFIER_OF_TYPE
-
-template <typename T>
-std::enable_if_t<
- !std::is_null_pointer_v<decltype(kPrintfFormatSpecifierOfType<T>)>, String>
-ToString(T value) {
- auto size = std::snprintf(nullptr, 0, kPrintfFormatSpecifierOfType<T>, value);
- assert(size > 0);
- std::vector<char> buffer(size + 1);
- size = std::snprintf(buffer.data(), size + 1, kPrintfFormatSpecifierOfType<T>,
- value);
- assert(size > 0);
- return String::FromUtf8(buffer.data(), size);
-}
-
-template <typename T>
-String ToString(const T& value, StringView option) {
- CRU_UNUSED(option)
- return ToString(value);
-}
-
-inline String ToString(String value) { return value; }
-
-namespace details {
-enum class FormatTokenType { PlaceHolder, Text };
-enum class FormatPlaceHolderType { None, Positioned, Named };
-
-struct FormatToken {
- static FormatToken Text() {
- return FormatToken{FormatTokenType::Text, {}, {}, 0, {}, {}};
- }
-
- static FormatToken NonePlaceHolder(String option) {
- return FormatToken(FormatTokenType::PlaceHolder, {},
- FormatPlaceHolderType::None, 0, {}, std::move(option));
- }
-
- static FormatToken PositionedPlaceHolder(int position, String option) {
- return FormatToken(FormatTokenType::PlaceHolder, {},
- FormatPlaceHolderType::Positioned, position, {},
- std::move(option));
- }
-
- static FormatToken NamedPlaceHolder(String name, String option) {
- return FormatToken(FormatTokenType::PlaceHolder, {},
- FormatPlaceHolderType::Named, 0, std::move(name),
- std::move(option));
- }
-
- FormatToken(FormatTokenType type, String data,
- FormatPlaceHolderType place_holder_type,
- int place_holder_position, String place_holder_name,
- String place_holder_option)
- : type(type),
- data(std::move(data)),
- place_holder_type(place_holder_type),
- place_holder_position(place_holder_position),
- place_holder_name(std::move(place_holder_name)),
- place_holder_option(std::move(place_holder_option)) {}
-
- CRU_DEFAULT_COPY(FormatToken)
- CRU_DEFAULT_MOVE(FormatToken)
-
- CRU_DEFAULT_DESTRUCTOR(FormatToken)
-
- FormatTokenType type;
- String data;
- FormatPlaceHolderType place_holder_type;
- int place_holder_position;
- String place_holder_name;
- String place_holder_option;
-};
-
-std::vector<FormatToken> CRU_BASE_API ParseToFormatTokenList(StringView str);
-
-void CRU_BASE_API FormatAppendFromFormatTokenList(
- String& current, const std::vector<FormatToken>& format_token_list,
- Index index);
-
-template <typename TA, typename... T>
-void FormatAppendFromFormatTokenList(
- String& current, const std::vector<FormatToken>& format_token_list,
- Index index, TA&& args0, T&&... args) {
- 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) {
- if (token.place_holder_type == FormatPlaceHolderType::None) {
- current += ToString(std::forward<TA>(args0), token.place_holder_option);
- FormatAppendFromFormatTokenList(current, format_token_list, i + 1,
- std::forward<T>(args)...);
-
- return;
- } else {
- throw Exception(
- "Currently do not support positional or named place holder.");
- }
- } else {
- current += token.data;
- }
- }
-}
-} // namespace details
-
-template <typename... T>
-String Format(StringView format, T&&... args) {
- String result;
-
- details::FormatAppendFromFormatTokenList(
- result, details::ParseToFormatTokenList(format), 0,
- std::forward<T>(args)...);
-
- return result;
-}
-
-template <typename... T>
-String String::Format(T&&... args) const {
- return cru::Format(*this, std::forward<T>(args)...);
-}
-
-template <typename T>
-struct ImplementFormatterByToUtf8String {
- template <class ParseContext>
- constexpr ParseContext::iterator parse(ParseContext& ctx) const {
- auto iter = ctx.begin();
- if (*iter != '}') {
- throw std::format_error(
- "ImplementFormatterByToUtf8String does not accept format args.");
- }
- return iter;
- }
-
- template <class FmtContext>
- FmtContext::iterator format(const T& object, FmtContext& ctx) const {
- return std::ranges::copy(ToUtf8String(object), ctx.out()).out;
- }
-};
-} // namespace cru
diff --git a/include/cru/base/String.h b/include/cru/base/String.h
deleted file mode 100644
index 313a3ce2..00000000
--- a/include/cru/base/String.h
+++ /dev/null
@@ -1,442 +0,0 @@
-#pragma once
-#include "Base.h"
-
-#include "Buffer.h"
-#include "Range.h"
-#include "StringUtil.h"
-
-#include <filesystem>
-#include <initializer_list>
-#include <iterator>
-#include <string>
-#include <string_view>
-#include <vector>
-
-namespace cru {
-class StringView;
-
-class CRU_BASE_API String {
- public:
- using value_type = char16_t;
- using size_type = Index;
- using difference_type = Index;
- using reference = value_type&;
- using const_reference = const value_type&;
- using pointer = value_type*;
- using const_pointer = const value_type*;
- using iterator = value_type*;
- using const_iterator = const value_type*;
- using reverse_iterator = std::reverse_iterator<iterator>;
- using const_reverse_iterator = std::reverse_iterator<const_iterator>;
-
- public:
- static String FromUtf8(const char* str);
- static String FromUtf8(const char* str, Index size);
- static String FromUtf8(const std::byte* str, Index size);
- static String FromUtf8(std::string_view str) {
- return FromUtf8(str.data(), str.size());
- }
- static String FromUtf8(const Buffer& buffer);
-
- static String FromUtf16(const char16_t* str) { return String(str); }
- static String FromUtf16(const char16_t* str, Index size) {
- return String(str, size);
- }
- static String FromUtf16(std::u16string_view str) {
- return FromUtf16(str.data(), str.size());
- }
-
- static inline String From(StringView str);
-
- // Never use this if you don't know what this mean!
- static String FromBuffer(pointer buffer, Index size, Index capacity) {
- return String{from_buffer_tag{}, buffer, size, capacity};
- }
-
- static String FromStdPath(const std::filesystem::path& path);
-
-#ifdef CRU_PLATFORM_WINDOWS
- static String FromUtf16(wchar_t* str) { return String(str); }
- static String FromUtf16(wchar_t* str, Index size) {
- return String(str, size);
- }
-#endif
-
- public:
- String();
-
- String(const_pointer str);
- String(const_pointer str, size_type size);
-
- template <Index size>
- String(const char16_t (&str)[size])
- : String(reinterpret_cast<const_pointer>(str), size - 1) {}
-
- template <typename Iter>
- String(Iter start, Iter end): String() {
- for (; start != end; start++) {
- append(*start);
- }
- }
-
- String(size_type size, value_type ch = 0);
-
- String(std::initializer_list<value_type> l);
-
- explicit String(StringView str);
-
-#ifdef CRU_PLATFORM_WINDOWS
- String(const wchar_t* str);
- String(const wchar_t* str, Index size);
- String(const std::wstring& str) : String(str.data(), str.size()) {}
-#endif
-
- String(const String& other);
- String(String&& other) noexcept;
-
- String& operator=(const String& other);
- String& operator=(String&& other) noexcept;
-
- ~String();
-
- private:
- struct from_buffer_tag {};
- String(from_buffer_tag, pointer buffer, Index size, Index capacity);
-
- public:
- bool empty() const { return this->size_ == 0; }
- Index size() const { return this->size_; }
- Index length() const { return this->size(); }
- Index capacity() const { return this->capacity_; }
- pointer data() { return this->buffer_; }
- const_pointer data() const { return this->buffer_; }
-
- void resize(Index new_size);
- void reserve(Index new_capacity);
- void shrink_to_fit();
-
- reference front() { return this->operator[](0); }
- const_reference front() const { return this->operator[](0); }
-
- reference back() { return this->operator[](size_ - 1); }
- const_reference back() const { return this->operator[](size_ - 1); }
-
- const_pointer c_str() const { return buffer_; }
-
- reference operator[](Index index) { return buffer_[index]; }
- const_reference operator[](Index index) const { return buffer_[index]; }
-
- public:
- iterator begin() { return this->buffer_; }
- const_iterator begin() const { return this->buffer_; }
- const_iterator cbegin() const { return this->buffer_; }
-
- iterator end() { return this->buffer_ + this->size_; }
- const_iterator end() const { return this->buffer_ + this->size_; }
- const_iterator cend() const { return this->buffer_ + this->size_; }
-
- reverse_iterator rbegin() { return reverse_iterator{end()}; }
- const_reverse_iterator rbegin() const {
- return const_reverse_iterator{end()};
- }
- const_reverse_iterator crbegin() const {
- return const_reverse_iterator{cend()};
- }
-
- reverse_iterator rend() { return reverse_iterator{begin()}; }
- const_reverse_iterator rend() const {
- return const_reverse_iterator{begin()};
- }
- const_reverse_iterator crend() const {
- return const_reverse_iterator{cbegin()};
- }
-
- public:
- void clear();
- iterator insert(const_iterator pos, value_type value) {
- return this->insert(pos, &value, 1);
- }
- iterator insert(const_iterator pos, const_iterator str, Index size);
- iterator insert(const_iterator pos, StringView str);
- iterator erase(const_iterator pos) { return this->erase(pos, pos + 1); }
- iterator erase(const_iterator start, const_iterator end);
- void push_back(value_type value) { this->append(value); }
- void pop_back() { this->erase(cend() - 1); }
- void append(value_type value) { this->insert(cend(), value); }
- void append(const_iterator str, Index size) {
- this->insert(cend(), str, size);
- }
- inline void append(StringView str);
-
- String substr(size_type start, size_type size = -1) const {
- if (size == -1) {
- size = this->size_ - start;
- }
- return String(this->buffer_ + start, size);
- }
-
- String& operator+=(value_type value) {
- this->append(value);
- return *this;
- }
- String& operator+=(StringView other);
-
- public:
- operator std::u16string_view() const {
- return std::u16string_view(data(), size());
- }
-
- StringView View() const;
-
- public:
- Index Find(value_type value, Index start = 0) const;
- std::vector<String> Split(value_type separator,
- bool remove_space_line = false) const;
- std::vector<String> SplitToLines(bool remove_space_line = false) const;
-
- bool StartWith(StringView str) const;
- bool EndWith(StringView str) const;
-
- String& TrimStart();
- String& TrimEnd();
- String& Trim();
-
- public:
- void AppendCodePoint(CodePoint code_point);
-
- Utf16CodePointIterator CodePointIterator() const {
- return Utf16CodePointIterator(buffer_, size_);
- }
-
- Index IndexFromCodeUnitToCodePoint(Index code_unit_index) const;
- Index IndexFromCodePointToCodeUnit(Index code_point_index) const;
- Range RangeFromCodeUnitToCodePoint(Range code_unit_range) const;
- Range RangeFromCodePointToCodeUnit(Range code_point_range) const;
-
-#ifdef CRU_PLATFORM_WINDOWS
- const wchar_t* WinCStr() const {
- return reinterpret_cast<const wchar_t*>(c_str());
- }
-#endif
-
- template <typename... T>
- String Format(T&&... args) const;
-
- std::string ToUtf8() const;
- Buffer ToUtf8Buffer(bool end_zero = true) const;
-
- int Compare(const String& other) const;
- int CaseInsensitiveCompare(const String& other) const;
- bool CaseInsensitiveEqual(const String& other) const {
- return CaseInsensitiveCompare(other) == 0;
- }
-
- private:
- char16_t* buffer_;
- Index size_; // not including trailing '\0'
- Index capacity_; // always 1 smaller than real buffer size
-};
-CRU_BASE_API
-std::ostream& operator<<(std::ostream& os, const String& value);
-
-class CRU_BASE_API StringView {
- public:
- using value_type = char16_t;
- using size_type = Index;
- using difference_type = Index;
- using reference = value_type&;
- using const_reference = const value_type&;
- using pointer = value_type*;
- using const_pointer = const value_type*;
- using iterator = const value_type*;
- using const_iterator = const value_type*;
- using reverse_iterator = std::reverse_iterator<iterator>;
- using const_reverse_iterator = std::reverse_iterator<const_iterator>;
-
- StringView() = default;
-
- constexpr StringView(const_pointer ptr, Index size)
- : ptr_(ptr), size_(size) {}
-
- template <Index size>
- constexpr StringView(const value_type (&array)[size])
- : StringView(array, size - 1) {}
-
- StringView(const String& str) : StringView(str.data(), str.size()) {}
-
- CRU_DEFAULT_COPY(StringView)
- CRU_DEFAULT_MOVE(StringView)
-
- ~StringView() = default;
-
- bool empty() const { return size_ == 0; }
- Index size() const { return size_; }
- const value_type* data() const { return ptr_; }
-
- public:
- iterator begin() { return this->ptr_; }
- const_iterator begin() const { return this->ptr_; }
- const_iterator cbegin() const { return this->ptr_; }
-
- iterator end() { return this->ptr_ + this->size_; }
- const_iterator end() const { return this->ptr_ + this->size_; }
- const_iterator cend() const { return this->ptr_ + this->size_; }
-
- reverse_iterator rbegin() { return reverse_iterator{end()}; }
- const_reverse_iterator rbegin() const {
- return const_reverse_iterator{end()};
- }
- const_reverse_iterator crbegin() const {
- return const_reverse_iterator{cend()};
- }
-
- reverse_iterator rend() { return reverse_iterator{begin()}; }
- const_reverse_iterator rend() const {
- return const_reverse_iterator{begin()};
- }
- const_reverse_iterator crend() const {
- return const_reverse_iterator{cbegin()};
- }
-
- StringView substr(Index pos);
- StringView substr(Index pos, Index size);
-
- value_type operator[](Index index) const { return ptr_[index]; }
-
- operator std::u16string_view() const {
- return std::u16string_view(data(), size());
- }
-
- public:
- int Compare(const StringView& other) const;
- int CaseInsensitiveCompare(const StringView& other) const;
- bool CaseInsensitiveEqual(const StringView& other) const {
- return CaseInsensitiveCompare(other) == 0;
- }
-
- String ToString() const { return String(ptr_, size_); }
-
- Utf16CodePointIterator CodePointIterator() const {
- return Utf16CodePointIterator(ptr_, size_);
- }
-
- Index Find(value_type value, Index start = 0) const;
- std::vector<String> Split(value_type separator,
- bool remove_space_line = false) const;
- std::vector<String> SplitToLines(bool remove_space_line = false) const;
-
- bool StartWith(StringView str) const;
- bool EndWith(StringView str) const;
-
- Index IndexFromCodeUnitToCodePoint(Index code_unit_index) const;
- Index IndexFromCodePointToCodeUnit(Index code_point_index) const;
- Range RangeFromCodeUnitToCodePoint(Range code_unit_range) const;
- Range RangeFromCodePointToCodeUnit(Range code_point_range) const;
-
- std::string ToUtf8() const;
- Buffer ToUtf8Buffer(bool end_zero = true) const;
-
- private:
- const char16_t* ptr_;
- Index size_;
-};
-
-CRU_DEFINE_COMPARE_OPERATORS(String)
-
-inline String operator+(const String& left, const String& right) {
- String result;
- result += left;
- result += right;
- return result;
-}
-
-inline String operator+(String::value_type left, const String& right) {
- String result;
- result += left;
- result += right;
- return result;
-}
-
-inline String operator+(const String& left, String::value_type right) {
- String result;
- result += left;
- result += right;
- return result;
-}
-
-CRU_DEFINE_COMPARE_OPERATORS(StringView)
-
-inline String::iterator String::insert(const_iterator pos, StringView str) {
- return insert(pos, str.data(), str.size());
-}
-
-inline void String::append(StringView str) {
- this->append(str.data(), str.size());
-}
-
-inline String String::From(StringView str) { return str.ToString(); }
-
-inline String::String(StringView str) : String(str.data(), str.size()) {}
-
-inline String ToString(StringView value) { return value.ToString(); }
-
-inline CodePoint Utf16PreviousCodePoint(StringView str, Index current,
- Index* previous_position) {
- return Utf16PreviousCodePoint(str.data(), str.size(), current,
- previous_position);
-}
-
-inline CodePoint Utf16NextCodePoint(StringView str, Index current,
- Index* next_position) {
- return Utf16NextCodePoint(str.data(), str.size(), current, next_position);
-}
-
-inline bool Utf16IsValidInsertPosition(StringView str, Index position) {
- return Utf16IsValidInsertPosition(str.data(), str.size(), position);
-}
-
-// Return position after the character making predicate returns true or 0 if no
-// character doing so.
-inline Index CRU_BASE_API
-Utf16BackwardUntil(StringView str, Index position,
- const std::function<bool(CodePoint)>& predicate) {
- return Utf16BackwardUntil(str.data(), str.size(), position, predicate);
-}
-// Return position before the character making predicate returns true or
-// str.size() if no character doing so.
-inline Index CRU_BASE_API
-Utf16ForwardUntil(StringView str, Index position,
- const std::function<bool(CodePoint)>& predicate) {
- return Utf16ForwardUntil(str.data(), str.size(), position, predicate);
-}
-
-inline Index Utf16PreviousWord(StringView str, Index position,
- bool* is_space = nullptr) {
- return Utf16PreviousWord(str.data(), str.size(), position, is_space);
-}
-
-inline Index Utf16NextWord(StringView str, Index position,
- bool* is_space = nullptr) {
- return Utf16NextWord(str.data(), str.size(), position, is_space);
-}
-
-String CRU_BASE_API ToLower(StringView s);
-String CRU_BASE_API ToUpper(StringView s);
-
-} // namespace cru
-
-template <>
-struct std::hash<cru::String> {
- std::size_t operator()(const cru::String& value) const {
- return std::hash<std::u16string_view>{}(std::u16string_view(
- reinterpret_cast<const char16_t*>(value.data()), value.size()));
- }
-};
-
-template <>
-struct std::hash<cru::StringView> {
- std::size_t operator()(const cru::StringView& value) const {
- return std::hash<std::u16string_view>{}(std::u16string_view(
- reinterpret_cast<const char16_t*>(value.data()), value.size()));
- }
-};
diff --git a/include/cru/base/StringUtil.h b/include/cru/base/StringUtil.h
index 258d884e..7a88f7e8 100644
--- a/include/cru/base/StringUtil.h
+++ b/include/cru/base/StringUtil.h
@@ -111,10 +111,10 @@ std::vector<T> ParseToNumberList(std::string_view str,
auto segs = Split(str, separator, SplitOptions::RemoveSpace);
std::vector<T> result;
for (const auto& seg : segs) {
- result.push_back(
- ParseToNumber<T>(Trim(seg), ParseToNumberFlags::AllowLeadingSpaces |
- ParseToNumberFlags::AllowTrailingSpaces)
- .value);
+ auto r = ParseToNumber<T>(Trim(seg),
+ ParseToNumberFlags::AllowLeadingSpaces |
+ ParseToNumberFlags::AllowTrailingSpaces);
+ result.push_back(r.value);
}
return result;
}
diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h
index 10d90060..5e24a159 100644
--- a/include/cru/ui/ThemeManager.h
+++ b/include/cru/ui/ThemeManager.h
@@ -1,7 +1,6 @@
#pragma once
#include "Base.h"
#include "cru/base/Event.h"
-#include "cru/base/Format.h"
#include "cru/ui/ThemeResourceDictionary.h"
#include <vector>
@@ -27,7 +26,7 @@ class CRU_UI_API ThemeManager : public Object {
std::unique_ptr<ThemeResourceDictionary> theme_resource_dictionary);
template <typename T>
- T GetResource(std::string_view key) {
+ T GetResource(const std::string_view& key) {
for (const auto& resource_dictionary : theme_resource_dictionary_list_) {
try {
return resource_dictionary->GetResource<T>(key);
diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h
index 90cbe520..e7463b12 100644
--- a/include/cru/ui/ThemeResourceDictionary.h
+++ b/include/cru/ui/ThemeResourceDictionary.h
@@ -28,11 +28,7 @@ class CRU_UI_API ThemeResourceDictionary : public Object {
public:
static std::unique_ptr<ThemeResourceDictionary> FromFile(
- const String& file_path);
- static std::unique_ptr<ThemeResourceDictionary> FromFile(
- std::filesystem::path file_path) {
- return FromFile(String::FromStdPath(file_path));
- }
+ std::filesystem::path file_path);
explicit ThemeResourceDictionary(xml::XmlElementNode* xml_root,
bool clone = true);
diff --git a/include/cru/ui/controls/Button.h b/include/cru/ui/controls/Button.h
index 717710e8..3c01be32 100644
--- a/include/cru/ui/controls/Button.h
+++ b/include/cru/ui/controls/Button.h
@@ -12,7 +12,7 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>,
public virtual IClickableControl,
public virtual IBorderControl {
public:
- static constexpr StringView kControlType = u"Button";
+ static constexpr std::string_view kControlType = "Button";
public:
Button();
@@ -22,7 +22,7 @@ class CRU_UI_API Button : public SingleChildControl<render::BorderRenderObject>,
Button& operator=(Button&& other) = delete;
~Button() override;
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
public:
helper::ClickState GetClickState() override {
diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h
index 19908389..8a2c84a0 100644
--- a/include/cru/ui/controls/CheckBox.h
+++ b/include/cru/ui/controls/CheckBox.h
@@ -12,12 +12,12 @@ class CRU_UI_API CheckBox : public NoChildControl,
public virtual ICheckableControl,
public virtual IClickableControl {
public:
- static constexpr StringView kControlType = u"CheckBox";
+ static constexpr std::string_view kControlType = "CheckBox";
CheckBox();
~CheckBox() override;
- String GetControlType() const override { return kControlType.ToString(); }
+ std::string GetControlType() const override { return std::string(kControlType); }
render::RenderObject* GetRenderObject() const override {
return container_render_object_.get();
diff --git a/include/cru/ui/controls/Container.h b/include/cru/ui/controls/Container.h
index c8bf3f32..4fee178d 100644
--- a/include/cru/ui/controls/Container.h
+++ b/include/cru/ui/controls/Container.h
@@ -8,7 +8,7 @@ namespace cru::ui::controls {
class CRU_UI_API Container
: public SingleChildControl<render::BorderRenderObject>,
public virtual IBorderControl {
- static constexpr StringView kControlType = u"Container";
+ static constexpr std::string_view kControlType = "Container";
public:
Container();
@@ -46,6 +46,6 @@ class CRU_UI_API Container
}
public:
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h
index f6603bbc..7301ecd8 100644
--- a/include/cru/ui/controls/Control.h
+++ b/include/cru/ui/controls/Control.h
@@ -36,7 +36,7 @@ class CRU_UI_API Control : public Object,
~Control() override;
public:
- virtual String GetControlType() const = 0;
+ virtual std::string GetControlType() const = 0;
//*************** region: tree ***************
public:
diff --git a/include/cru/ui/controls/FlexLayout.h b/include/cru/ui/controls/FlexLayout.h
index 148586c0..8940e38e 100644
--- a/include/cru/ui/controls/FlexLayout.h
+++ b/include/cru/ui/controls/FlexLayout.h
@@ -13,7 +13,7 @@ using render::FlexMainAlignment;
class CRU_UI_API FlexLayout
: public LayoutControl<render::FlexLayoutRenderObject> {
public:
- static constexpr StringView kControlType = u"FlexLayout";
+ static constexpr std::string_view kControlType = "FlexLayout";
public:
FlexLayout();
@@ -23,7 +23,7 @@ class CRU_UI_API FlexLayout
FlexLayout& operator=(FlexLayout&& other) = delete;
~FlexLayout() override;
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
FlexMainAlignment GetContentMainAlign() const;
void SetContentMainAlign(FlexMainAlignment value);
diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h
index 9dbb3a3d..9e7572e0 100644
--- a/include/cru/ui/controls/IconButton.h
+++ b/include/cru/ui/controls/IconButton.h
@@ -17,14 +17,14 @@ class CRU_UI_API IconButton : public NoChildControl,
public virtual IBorderControl,
public virtual IContentBrushControl {
public:
- static constexpr StringView kControlType = u"IconButton";
+ static constexpr std::string_view kControlType = "IconButton";
public:
IconButton();
IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port);
~IconButton() override;
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
render::RenderObject* GetRenderObject() const override {
return container_render_object_.get();
diff --git a/include/cru/ui/controls/Popup.h b/include/cru/ui/controls/Popup.h
index 464e7278..7c57d257 100644
--- a/include/cru/ui/controls/Popup.h
+++ b/include/cru/ui/controls/Popup.h
@@ -8,7 +8,7 @@
namespace cru::ui::controls {
class CRU_UI_API Popup : public RootControl {
public:
- static constexpr StringView kControlType = u"Popup";
+ static constexpr std::string_view kControlType = "Popup";
explicit Popup(Control* attached_control = nullptr);
@@ -17,6 +17,6 @@ class CRU_UI_API Popup : public RootControl {
~Popup() override;
- String GetControlType() const override { return kControlType.ToString(); }
+ std::string GetControlType() const override { return std::string(kControlType); }
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/ScrollView.h b/include/cru/ui/controls/ScrollView.h
index 244977d5..cefda747 100644
--- a/include/cru/ui/controls/ScrollView.h
+++ b/include/cru/ui/controls/ScrollView.h
@@ -7,7 +7,7 @@ namespace cru::ui::controls {
class CRU_UI_API ScrollView
: public SingleChildControl<render::ScrollRenderObject> {
public:
- static constexpr StringView kControlType = u"ScrollView";
+ static constexpr std::string_view kControlType = "ScrollView";
ScrollView();
CRU_DELETE_COPY(ScrollView)
@@ -15,6 +15,6 @@ class CRU_UI_API ScrollView
~ScrollView() override;
public:
- String GetControlType() const override { return kControlType.ToString(); }
+ std::string GetControlType() const override { return std::string(kControlType); }
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/StackLayout.h b/include/cru/ui/controls/StackLayout.h
index cbf35cbe..db646807 100644
--- a/include/cru/ui/controls/StackLayout.h
+++ b/include/cru/ui/controls/StackLayout.h
@@ -9,13 +9,13 @@ using render::StackChildLayoutData;
class CRU_UI_API StackLayout
: public LayoutControl<render::StackLayoutRenderObject> {
public:
- static constexpr StringView kControlType = u"StackLayout";
+ static constexpr std::string_view kControlType = "StackLayout";
StackLayout();
CRU_DELETE_COPY(StackLayout)
CRU_DELETE_MOVE(StackLayout)
~StackLayout() override;
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/TextBlock.h b/include/cru/ui/controls/TextBlock.h
index 66330b23..a3b6407f 100644
--- a/include/cru/ui/controls/TextBlock.h
+++ b/include/cru/ui/controls/TextBlock.h
@@ -14,7 +14,7 @@ class CRU_UI_API TextBlock : public NoChildControl,
public virtual IFontControl,
public virtual IContentBrushControl {
public:
- static constexpr StringView kControlType = u"TextBlock";
+ static constexpr std::string_view kControlType = "TextBlock";
static std::unique_ptr<TextBlock> Create(std::string text,
bool selectable = false) {
@@ -32,7 +32,7 @@ class CRU_UI_API TextBlock : public NoChildControl,
TextBlock& operator=(TextBlock&& other) = delete;
~TextBlock() override;
- String GetControlType() const final { return kControlType.ToString(); }
+ std::string GetControlType() const final { return std::string(kControlType); }
render::RenderObject* GetRenderObject() const override;
diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h
index 13f5d356..adb9895e 100644
--- a/include/cru/ui/controls/TextBox.h
+++ b/include/cru/ui/controls/TextBox.h
@@ -18,14 +18,14 @@ class CRU_UI_API TextBox : public NoChildControl,
public virtual IContentBrushControl,
public virtual IFontControl {
public:
- static constexpr StringView control_type = u"TextBox";
+ static constexpr std::string_view control_type = "TextBox";
TextBox();
CRU_DELETE_COPY(TextBox)
CRU_DELETE_MOVE(TextBox)
~TextBox() override;
- String GetControlType() const final { return control_type.ToString(); }
+ std::string GetControlType() const final { return std::string(control_type); }
render::RenderObject* GetRenderObject() const override;
diff --git a/include/cru/ui/controls/TreeView.h b/include/cru/ui/controls/TreeView.h
index 6c3c360b..dc74750a 100644
--- a/include/cru/ui/controls/TreeView.h
+++ b/include/cru/ui/controls/TreeView.h
@@ -52,14 +52,16 @@ class CRU_UI_API TreeViewItem : public Object {
class CRU_UI_API TreeView : public Control {
public:
- constexpr static StringView kControlType = u"TreeView";
+ constexpr static std::string_view kControlType = "TreeView";
TreeView();
CRU_DELETE_COPY(TreeView)
CRU_DELETE_MOVE(TreeView)
~TreeView() override;
- String GetControlType() const override { return kControlType.ToString(); }
+ std::string GetControlType() const override {
+ return std::string(kControlType);
+ }
render::TreeRenderObject* GetRenderObject() { return &render_object_; }
void ForEachChild(const std::function<void(Control*)>& predicate) override;
diff --git a/include/cru/ui/controls/Window.h b/include/cru/ui/controls/Window.h
index 656a96dd..c4ba94d9 100644
--- a/include/cru/ui/controls/Window.h
+++ b/include/cru/ui/controls/Window.h
@@ -1,5 +1,4 @@
#pragma once
-#include "cru/platform/gui/Base.h"
#include "cru/ui/controls/RootControl.h"
#include "cru/base/Base.h"
@@ -7,7 +6,7 @@
namespace cru::ui::controls {
class CRU_UI_API Window final : public RootControl {
public:
- static constexpr StringView control_type = u"Window";
+ static constexpr std::string_view control_type = "Window";
public:
explicit Window(Control* attached_control = nullptr);
@@ -16,6 +15,6 @@ class CRU_UI_API Window final : public RootControl {
~Window() override;
public:
- String GetControlType() const final { return control_type.ToString(); }
+ std::string GetControlType() const final { return std::string(control_type); }
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/document/DocumentElementType.h b/include/cru/ui/document/DocumentElementType.h
index 6d4958d0..3621bbd9 100644
--- a/include/cru/ui/document/DocumentElementType.h
+++ b/include/cru/ui/document/DocumentElementType.h
@@ -1,26 +1,25 @@
#pragma once
#include "../Base.h"
-#include "cru/base/String.h"
#include <vector>
namespace cru::ui::document {
class CRU_UI_API DocumentElementType : public Object {
public:
- explicit DocumentElementType(String name,
+ explicit DocumentElementType(std::string name,
std::vector<DocumentElementType*> parents);
~DocumentElementType() override;
public:
- String GetName() const { return name_; }
+ std::string GetName() const { return name_; }
const std::vector<DocumentElementType*>& GetParents() const {
return parents_;
}
private:
- String name_;
+ std::string name_;
std::vector<DocumentElementType*> parents_;
};
diff --git a/include/cru/ui/document/TextDocumentElement.h b/include/cru/ui/document/TextDocumentElement.h
index 73a041ef..85ea6f2e 100644
--- a/include/cru/ui/document/TextDocumentElement.h
+++ b/include/cru/ui/document/TextDocumentElement.h
@@ -24,12 +24,12 @@ struct IDocumentLink : virtual Interface {
class CRU_UI_API TextDocumentElement : public DocumentElement {
public:
- TextDocumentElement(String text, TextStyle style, IDocumentLink* link);
+ TextDocumentElement(std::string text, TextStyle style, IDocumentLink* link);
~TextDocumentElement() override;
- String GetText() const { return text_; }
- void SetText(String text);
+ std::string GetText() const { return text_; }
+ void SetText(std::string text);
TextStyle GetStyle() const { return style_; }
void SetStyle(TextStyle style);
@@ -38,7 +38,7 @@ class CRU_UI_API TextDocumentElement : public DocumentElement {
void SetLink(IDocumentLink link);
private:
- String text_;
+ std::string text_;
TextStyle style_;
IDocumentLink* link_;
};
diff --git a/include/cru/ui/mapper/StringMapper.h b/include/cru/ui/mapper/StringMapper.h
index 01f58c77..e41ee0f9 100644
--- a/include/cru/ui/mapper/StringMapper.h
+++ b/include/cru/ui/mapper/StringMapper.h
@@ -1,10 +1,10 @@
#pragma once
#include "Mapper.h"
-#include <cru/base/String.h>
+#include <string>
namespace cru::ui::mapper {
-class CRU_UI_API StringMapper : public BasicMapper<String> {
+class CRU_UI_API StringMapper : public BasicMapper<std::string> {
public:
StringMapper();
~StringMapper();
@@ -14,7 +14,7 @@ class CRU_UI_API StringMapper : public BasicMapper<String> {
bool SupportMapFromXml() override { return true; }
protected:
- String DoMapFromString(std::string str) override;
- String DoMapFromXml(xml::XmlElementNode* node) override;
+ std::string DoMapFromString(std::string str) override;
+ std::string DoMapFromXml(xml::XmlElementNode* node) override;
};
} // namespace cru::ui::mapper
diff --git a/include/cru/ui/render/BorderRenderObject.h b/include/cru/ui/render/BorderRenderObject.h
index 7bfa4290..001494a6 100644
--- a/include/cru/ui/render/BorderRenderObject.h
+++ b/include/cru/ui/render/BorderRenderObject.h
@@ -50,7 +50,7 @@ class CRU_UI_API BorderRenderObject : public SingleChildRenderObject {
Rect GetPaddingRect() const override;
Rect GetContentRect() const override;
- String GetName() const override;
+ std::string GetName() const override;
protected:
Size OnMeasureContent(const MeasureRequirement& requirement,
diff --git a/include/cru/ui/render/FlexLayoutRenderObject.h b/include/cru/ui/render/FlexLayoutRenderObject.h
index 6c65ace3..bf68720a 100644
--- a/include/cru/ui/render/FlexLayoutRenderObject.h
+++ b/include/cru/ui/render/FlexLayoutRenderObject.h
@@ -104,7 +104,7 @@ class CRU_UI_API FlexLayoutRenderObject
FlexLayoutRenderObject& operator=(FlexLayoutRenderObject&& other) = delete;
~FlexLayoutRenderObject() override = default;
- String GetName() const override;
+ std::string GetName() const override;
FlexDirection GetFlexDirection() const { return direction_; }
void SetFlexDirection(FlexDirection direction) {
diff --git a/include/cru/ui/render/MeasureRequirement.h b/include/cru/ui/render/MeasureRequirement.h
index 544e0788..43bd3326 100644
--- a/include/cru/ui/render/MeasureRequirement.h
+++ b/include/cru/ui/render/MeasureRequirement.h
@@ -1,8 +1,6 @@
#pragma once
#include "../Base.h"
-#include "cru/base/String.h"
-
#include <algorithm>
#include <format>
#include <limits>
@@ -113,13 +111,11 @@ class MeasureLength final {
}
}
- std::string ToDebugStringUtf8() const {
+ std::string ToDebugString() const {
return IsSpecified() ? std::to_string(GetLengthOrUndefined())
: "UNSPECIFIED";
}
- String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
-
private:
// -1 for not specify
float length_;
@@ -168,13 +164,11 @@ struct MeasureSize {
};
}
- std::string ToDebugStringUtf8() const {
- return std::format("({}, {})", width.ToDebugStringUtf8(),
- height.ToDebugStringUtf8());
+ std::string ToDebugString() const {
+ return std::format("({}, {})", width.ToDebugString(),
+ height.ToDebugString());
}
- String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
-
constexpr static MeasureSize NotSpecified() {
return MeasureSize{MeasureLength::NotSpecified(),
MeasureLength::NotSpecified()};
@@ -241,13 +235,11 @@ struct MeasureRequirement {
return result;
}
- std::string ToDebugStringUtf8() const {
- return std::format("{{min: {}, max: {}}}", min.ToDebugStringUtf8(),
- max.ToDebugStringUtf8());
+ std::string ToDebugString() const {
+ return std::format("{{min: {}, max: {}}}", min.ToDebugString(),
+ max.ToDebugString());
}
- String ToDebugString() const { return String::FromUtf8(ToDebugStringUtf8()); }
-
constexpr static MeasureRequirement Merge(const MeasureRequirement& left,
const MeasureRequirement& right) {
return MeasureRequirement{MeasureSize::Min(left.max, right.max),
diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h
index eba3b6c4..266045e3 100644
--- a/include/cru/ui/render/RenderObject.h
+++ b/include/cru/ui/render/RenderObject.h
@@ -2,7 +2,6 @@
#include "../Base.h"
#include "MeasureRequirement.h"
-#include "cru/base/String.h"
#include <cru/platform/graphics/Painter.h>
@@ -145,8 +144,8 @@ class CRU_UI_API RenderObject : public Object {
void InvalidatePaint();
public:
- virtual String GetName() const;
- String GetDebugPathInTree() const;
+ virtual std::string GetName() const;
+ std::string GetDebugPathInTree() const;
protected:
// Size measure including margin and padding. Please reduce margin and padding
diff --git a/include/cru/ui/render/ScrollRenderObject.h b/include/cru/ui/render/ScrollRenderObject.h
index 180e927a..63a49aa3 100644
--- a/include/cru/ui/render/ScrollRenderObject.h
+++ b/include/cru/ui/render/ScrollRenderObject.h
@@ -60,7 +60,7 @@ class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject {
// Param margin is just for convenience and it will just add to the rect.
void ScrollToContain(const Rect& rect, const Thickness& margin = Thickness{});
- String GetName() const override { return u"ScrollRenderObject"; }
+ std::string GetName() const override { return "ScrollRenderObject"; }
bool IsMouseWheelScrollEnabled() const { return is_mouse_wheel_enabled_; }
void SetMouseWheelScrollEnabled(bool enable);
diff --git a/include/cru/ui/render/StackLayoutRenderObject.h b/include/cru/ui/render/StackLayoutRenderObject.h
index 515e8f43..0d75d032 100644
--- a/include/cru/ui/render/StackLayoutRenderObject.h
+++ b/include/cru/ui/render/StackLayoutRenderObject.h
@@ -36,7 +36,7 @@ class CRU_UI_API StackLayoutRenderObject
CRU_DELETE_MOVE(StackLayoutRenderObject)
~StackLayoutRenderObject() = default;
- String GetName() const override { return u"StackLayoutRenderObject"; }
+ std::string GetName() const override { return "StackLayoutRenderObject"; }
Alignment GetDefaultHorizontalAlignment() const {
return default_vertical_alignment_;
diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h
index b8d1882d..5b99ae98 100644
--- a/include/cru/ui/render/TextRenderObject.h
+++ b/include/cru/ui/render/TextRenderObject.h
@@ -93,7 +93,7 @@ class CRU_UI_API TextRenderObject : public RenderObject {
RenderObject* HitTest(const Point& point) override;
- String GetName() const override { return u"TextRenderObject"; }
+ std::string GetName() const override { return "TextRenderObject"; }
void Draw(platform::graphics::IPainter* painter) override;
diff --git a/include/cru/ui/render/TreeRenderObject.h b/include/cru/ui/render/TreeRenderObject.h
index ef40f4d0..9cb8581e 100644
--- a/include/cru/ui/render/TreeRenderObject.h
+++ b/include/cru/ui/render/TreeRenderObject.h
@@ -57,7 +57,7 @@ class CRU_UI_API TreeRenderObject : public RenderObject {
CRU_DELETE_MOVE(TreeRenderObject)
~TreeRenderObject() override;
- String GetName() const override { return u"TreeRenderObject"; }
+ std::string GetName() const override { return "TreeRenderObject"; }
TreeRenderObjectItem* GetRootItem() { return root_item_; }
diff --git a/include/cru/ui/style/StyleRule.h b/include/cru/ui/style/StyleRule.h
index 1ae2f0f1..e7f4d390 100644
--- a/include/cru/ui/style/StyleRule.h
+++ b/include/cru/ui/style/StyleRule.h
@@ -4,9 +4,6 @@
#include "Styler.h"
#include "cru/base/ClonablePtr.h"
-#include <memory>
-#include <vector>
-
namespace cru::ui::style {
/**
* \brief An immutable style rule contains a condition and a styler.
@@ -16,13 +13,13 @@ class CRU_UI_API StyleRule : public Object {
public:
static ClonablePtr<StyleRule> Create(ClonablePtr<Condition> condition,
ClonablePtr<Styler> styler,
- String name = {}) {
+ std::string name = {}) {
return ClonablePtr<StyleRule>(new StyleRule(
std::move(condition), std::move(styler), std::move(name)));
}
StyleRule(ClonablePtr<Condition> condition, ClonablePtr<Styler> styler,
- String name = {});
+ std::string name = {});
CRU_DEFAULT_COPY(StyleRule)
CRU_DEFAULT_MOVE(StyleRule)
@@ -30,16 +27,17 @@ class CRU_UI_API StyleRule : public Object {
~StyleRule() override = default;
public:
- String GetName() const { return name_; }
+ std::string GetName() const { return name_; }
Condition* GetCondition() const { return condition_.get(); }
Styler* GetStyler() const { return styler_.get(); }
StyleRule WithNewCondition(ClonablePtr<Condition> condition,
- String name = {}) const {
+ std::string name = {}) const {
return StyleRule{std::move(condition), styler_, std::move(name)};
}
- StyleRule WithNewStyler(ClonablePtr<Styler> styler, String name = {}) const {
+ StyleRule WithNewStyler(ClonablePtr<Styler> styler,
+ std::string name = {}) const {
return StyleRule{condition_, std::move(styler), std::move(name)};
}
@@ -48,6 +46,6 @@ class CRU_UI_API StyleRule : public Object {
private:
ClonablePtr<Condition> condition_;
ClonablePtr<Styler> styler_;
- String name_;
+ std::string name_;
};
} // namespace cru::ui::style
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)) {}
diff --git a/test/base/CMakeLists.txt b/test/base/CMakeLists.txt
index 13a0a2cb..b008e1b3 100644
--- a/test/base/CMakeLists.txt
+++ b/test/base/CMakeLists.txt
@@ -3,7 +3,6 @@ add_executable(CruBaseTest
HandlerRegistryTest.cpp
PropertyTreeTest.cpp
SelfResolvableTest.cpp
- StringTest.cpp
StringUtilTest.cpp
SubProcessTest.cpp
)
diff --git a/test/base/StringTest.cpp b/test/base/StringTest.cpp
deleted file mode 100644
index 65fe0a99..00000000
--- a/test/base/StringTest.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-#include "cru/base/Format.h"
-#include "cru/base/String.h"
-
-#include <catch2/catch_test_macros.hpp>
-
-TEST_CASE("String Append", "[string]") {
- using cru::String;
-
- String s;
- s.append(u"ha");
- s.append(s);
- REQUIRE(s == String(u"haha"));
-}
-
-TEST_CASE("String IndexConvert", "[string]") {
- using cru::String;
-
- String s(u"123");
- REQUIRE(s.IndexFromCodePointToCodeUnit(1) == 1);
- REQUIRE(s.IndexFromCodeUnitToCodePoint(1) == 1);
- REQUIRE(s.IndexFromCodeUnitToCodePoint(3) == 3);
- REQUIRE(s.IndexFromCodeUnitToCodePoint(3) == 3);
-}
-
-TEST_CASE("String Format", "[string]") {
- using cru::Format;
- using cru::String;
-
- REQUIRE(Format(u"{} + {} = {}", 123, 321, 444) == String(u"123 + 321 = 444"));
-}
-
-TEST_CASE("String Trim", "[string]") {
- using cru::String;
- REQUIRE(String(u" abc ").Trim() == u"abc");
-}
-
-TEST_CASE("String SplitToLines", "[string]") {
- using cru::String;
-
- String s(u"abc\ndef\nghi");
- auto lines = s.SplitToLines();
- REQUIRE(lines.size() == 3);
- REQUIRE(lines[0] == String(u"abc"));
- REQUIRE(lines[1] == String(u"def"));
- REQUIRE(lines[2] == String(u"ghi"));
-}
-
-TEST_CASE("String SplitToLinesWithEmptyLine", "[string]") {
- using cru::String;
-
- String s(u"abc\n \ndef\n\nghi\n");
- auto lines = s.SplitToLines();
- REQUIRE(lines.size() == 6);
- REQUIRE(lines[0] == String(u"abc"));
- REQUIRE(lines[1] == String(u" "));
- REQUIRE(lines[2] == String(u"def"));
- REQUIRE(lines[3] == String(u""));
- REQUIRE(lines[4] == String(u"ghi"));
- REQUIRE(lines[5] == String(u""));
-}
-
-TEST_CASE("String SplitToLinesRemoveSpaceLine", "[string]") {
- using cru::String;
-
- String s(u"abc\n \ndef\n\nghi\n");
- auto lines = s.SplitToLines(true);
- REQUIRE(lines.size() == 3);
- REQUIRE(lines[0] == String(u"abc"));
- REQUIRE(lines[1] == String(u"def"));
- REQUIRE(lines[2] == String(u"ghi"));
-}
-
-TEST_CASE("StringView ToUtf8", "[string]") {
- using cru::StringView;
- StringView utf16_text = u"aπ你🤣!";
- std::string_view utf8_text = "aπ你🤣!";
-
- REQUIRE(utf16_text.ToUtf8() == utf8_text);
-}
-
-TEST_CASE("String FromUtf8", "[string]") {
- std::u16string_view utf16_text = u"aπ你🤣!";
- std::string_view utf8_text = "aπ你🤣!";
-
- REQUIRE(cru::String::FromUtf8(utf8_text) == utf16_text);
-}
diff --git a/test/base/StringUtilTest.cpp b/test/base/StringUtilTest.cpp
index 5951531d..2b12780c 100644
--- a/test/base/StringUtilTest.cpp
+++ b/test/base/StringUtilTest.cpp
@@ -1,4 +1,3 @@
-#include "cru/base/String.h"
#include "cru/base/StringUtil.h"
#include <catch2/catch_test_macros.hpp>