diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 10:01:30 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 10:01:30 +0800 |
commit | faf77949e19dc0d01f75bf8abb783eda70328048 (patch) | |
tree | 0448c642573157d79a984ab19b3396210e91acca | |
parent | 9e4419826b3e23c63567591701a2834a837da98e (diff) | |
download | cru-faf77949e19dc0d01f75bf8abb783eda70328048.tar.gz cru-faf77949e19dc0d01f75bf8abb783eda70328048.tar.bz2 cru-faf77949e19dc0d01f75bf8abb783eda70328048.zip |
Platform base no String.
-rw-r--r-- | include/cru/base/StringUtil.h | 21 | ||||
-rw-r--r-- | include/cru/platform/Color.h | 21 | ||||
-rw-r--r-- | include/cru/platform/GraphicsBase.h | 49 | ||||
-rw-r--r-- | src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp | 6 | ||||
-rw-r--r-- | src/platform/Color.cpp | 333 | ||||
-rw-r--r-- | src/ui/mapper/ColorMapper.cpp | 2 | ||||
-rw-r--r-- | test/platform/ColorTest.cpp | 12 |
7 files changed, 220 insertions, 224 deletions
diff --git a/include/cru/base/StringUtil.h b/include/cru/base/StringUtil.h index d79c0c23..0ce3802f 100644 --- a/include/cru/base/StringUtil.h +++ b/include/cru/base/StringUtil.h @@ -3,8 +3,8 @@ #include "Bitmask.h" #include <compare> +#include <format> #include <functional> -#include <stdexcept> #include <string> #include <string_view> #include <type_traits> @@ -30,6 +30,25 @@ struct SplitOptions { std::vector<std::string> Split(std::string_view str, std::string_view sep, SplitOption options = {}); + +template <typename T> +struct ImplementFormatterByToString { + template <class ParseContext> + constexpr ParseContext::iterator parse(ParseContext& ctx) const { + auto iter = ctx.begin(); + if (*iter != '}') { + throw std::format_error( + "ImplementFormatterByToString does not accept format args."); + } + return iter; + } + + template <class FmtContext> + FmtContext::iterator format(const T& object, FmtContext& ctx) const { + return std::ranges::copy(object.ToString(), ctx.out()).out; + } +}; + } // namespace string using CodePoint = std::int32_t; diff --git a/include/cru/platform/Color.h b/include/cru/platform/Color.h index 54308bbd..53252cc4 100644 --- a/include/cru/platform/Color.h +++ b/include/cru/platform/Color.h @@ -1,13 +1,11 @@ #pragma once #include "Base.h" -#include "cru/base/Base.h" -#include "cru/base/String.h" +#include <cru/base/Base.h> #include <cstdint> -#include <format> #include <optional> -#include <unordered_map> +#include <string_view> namespace cru::platform { struct CRU_PLATFORM_API Color { @@ -38,14 +36,14 @@ struct CRU_PLATFORM_API Color { float GetFloatBlue() const { return static_cast<float>(blue) / 255.f; } float GetFloatAlpha() const { return static_cast<float>(alpha) / 255.f; } - String ToString() const; + std::string ToString() const; std::uint8_t red; std::uint8_t green; std::uint8_t blue; std::uint8_t alpha; - static std::optional<Color> Parse(StringView string, + static std::optional<Color> Parse(std::string_view string, bool parse_predefined_color = true); }; @@ -251,16 +249,7 @@ struct std::hash<cru::platform::Color> { }; namespace cru::platform { -namespace details { -extern const std::unordered_map<StringView, Color> predefined_name_color_map; -} // namespace details - -std::optional<Color> GetPredefinedColorByName(StringView name); - -inline String ToString(const Color& color) { - return String::FromUtf8(std::format("rgba({}, {}, {}, {})", color.red, - color.green, color.blue, color.alpha)); -} +std::optional<Color> GetPredefinedColorByName(std::string_view name); struct CRU_PLATFORM_API HslColor { HslColor() = default; diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h index 79e539a3..23a95865 100644 --- a/include/cru/platform/GraphicsBase.h +++ b/include/cru/platform/GraphicsBase.h @@ -1,9 +1,8 @@ #pragma once #include "Base.h" -#include "cru/base/Format.h" -#include "cru/base/Range.h" -#include "cru/base/String.h" +#include <cru/base/Range.h> +#include <cru/base/StringUtil.h> #include <format> #include <limits> @@ -24,6 +23,10 @@ struct Point final { constexpr Point Negate() const { return Point(-x, -y); } + std::string ToString() const { + return std::format("Point(x: {}, y: {})", x, y); + } + float x = 0; float y = 0; }; @@ -40,14 +43,6 @@ constexpr bool operator==(const Point& left, const Point& right) { return left.x == right.x && left.y == right.y; } -inline std::string ToUtf8String(const Point& point) { - return std::format("Point(x: {}, y: {})", point.x, point.y); -} - -inline String ToString(const Point& point) { - return String::FromUtf8(ToUtf8String(point)); -} - struct Size final { static CRU_PLATFORM_API const Size kMax; static CRU_PLATFORM_API const Size kZero; @@ -63,6 +58,10 @@ struct Size final { std::numeric_limits<float>::max()}; } + std::string ToString() const { + return std::format("Size(width: {}, height: {})", width, height); + } + float width = 0; float height = 0; }; @@ -81,14 +80,6 @@ constexpr bool operator==(const Size& left, const Size& right) { return left.width == right.width && left.height == right.height; } -inline std::string ToUtf8String(const Size& size) { - return std::format("Size(width: {}, height: {})", size.width, size.height); -} - -inline String ToString(const Size& size) { - return String::FromUtf8(ToUtf8String(size)); -} - struct Thickness final { constexpr Thickness() : Thickness(0) {} @@ -230,6 +221,11 @@ struct Rect final { return result; } + std::string ToString() const { + return std::format("Rect(left: {}, top: {}, width: {}, height: {})", left, + top, width, height); + } + float left = 0.0f; float top = 0.0f; float width = 0.0f; @@ -241,15 +237,6 @@ constexpr bool operator==(const Rect& left, const Rect& right) { left.width == right.width && left.height == right.height; } -inline std::string ToUtf8String(const Rect& rect) { - return std::format("Rect(left: {}, top: {}, width: {}, height: {})", - rect.left, rect.top, rect.width, rect.height); -} - -inline String ToString(const Rect& rect) { - return String::FromUtf8(ToUtf8String(rect)); -} - struct RoundedRect final { constexpr RoundedRect() = default; constexpr RoundedRect(const Rect& rect, const float radius_x, @@ -295,12 +282,12 @@ using TextRange = Range; template <> struct std::formatter<cru::platform::Point, char> - : cru::ImplementFormatterByToUtf8String<cru::platform::Point> {}; + : cru::string::ImplementFormatterByToString<cru::platform::Point> {}; template <> struct std::formatter<cru::platform::Size, char> - : cru::ImplementFormatterByToUtf8String<cru::platform::Size> {}; + : cru::string::ImplementFormatterByToString<cru::platform::Size> {}; template <> struct std::formatter<cru::platform::Rect, char> - : cru::ImplementFormatterByToUtf8String<cru::platform::Rect> {}; + : cru::string::ImplementFormatterByToString<cru::platform::Rect> {}; diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp index e9e486ac..0fe3908e 100644 --- a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp +++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp @@ -20,12 +20,12 @@ ColorPropertyEditor::ColorPropertyEditor() { color_cube_.SetForegroundBrush(color_cube_brush_); - color_text_.SetText(color_.ToString()); + color_text_.SetText(String::FromUtf8(color_.ToString())); color_text_.SetMargin(ui::Thickness(10, 0, 0, 0)); color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { auto text = color_text_.GetTextView(); - auto color = ui::Color::Parse(text); + auto color = ui::Color::Parse(text.ToUtf8()); if (color) { color_ = *color; color_cube_brush_->SetColor(*color); @@ -43,6 +43,6 @@ ColorPropertyEditor::~ColorPropertyEditor() {} void ColorPropertyEditor::SetValue(const ui::Color &color, bool trigger_change) { if (!trigger_change) SuppressNextChangeEvent(); - color_text_.SetText(color.ToString()); + color_text_.SetText(String::FromUtf8(color.ToString())); } } // namespace cru::theme_builder::components::properties diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp index bbb78628..c4a10577 100644 --- a/src/platform/Color.cpp +++ b/src/platform/Color.cpp @@ -5,16 +5,16 @@ #include <optional> namespace cru::platform { -String Color::ToString() const { - auto to_hex = [](std::uint8_t v) -> char16_t { - return v >= 10 ? v - 10 + u'a' : v + u'0'; +std::string Color::ToString() const { + auto to_hex = [](std::uint8_t v) -> char { + return v >= 10 ? v - 10 + 'a' : v + '0'; }; - auto to_two_hex_digit = [to_hex](std::uint8_t v) -> String { + auto to_two_hex_digit = [to_hex](std::uint8_t v) -> std::string { return {to_hex(v /= 16), to_hex(v %= 16)}; }; - String result = u"#"; + std::string result = "#"; result.append(to_two_hex_digit(red)); result.append(to_two_hex_digit(green)); result.append(to_two_hex_digit(blue)); @@ -22,7 +22,7 @@ String Color::ToString() const { return result; } -std::optional<Color> Color::Parse(StringView string, +std::optional<Color> Color::Parse(std::string_view string, bool parse_predefined_color) { if (parse_predefined_color) { auto optional_predefined_color = GetPredefinedColorByName(string); @@ -31,14 +31,15 @@ std::optional<Color> Color::Parse(StringView string, } } - auto get_num = [](char16_t c) -> std::optional<int> { - if (c >= u'0' && c <= u'9') return c - u'0'; - if (c >= u'A' && c <= u'F') return c - u'A' + 10; - if (c >= u'a' && c <= u'f') return c - u'a' + 10; + auto get_num = [](char c) -> std::optional<int> { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; return std::nullopt; }; - auto get_num_for_two_digit = [get_num](StringView str) -> std::optional<int> { + auto get_num_for_two_digit = + [get_num](std::string_view str) -> std::optional<int> { int num = 0; auto d1 = get_num(str[0]); if (!d1) return std::nullopt; @@ -78,163 +79,163 @@ std::optional<Color> Color::Parse(StringView string, } } -namespace details { -const std::unordered_map<StringView, Color> predefined_name_color_map{ - {u"transparent", colors::transparent}, - {u"black", colors::black}, - {u"silver", colors::silver}, - {u"gray", colors::gray}, - {u"white", colors::white}, - {u"maroon", colors::maroon}, - {u"red", colors::red}, - {u"purple", colors::purple}, - {u"fuchsia", colors::fuchsia}, - {u"green", colors::green}, - {u"lime", colors::lime}, - {u"olive", colors::olive}, - {u"yellow", colors::yellow}, - {u"navy", colors::navy}, - {u"blue", colors::blue}, - {u"teal", colors::teal}, - {u"aqua", colors::aqua}, - {u"orange", colors::orange}, - {u"aliceblue", colors::aliceblue}, - {u"antiquewhite", colors::antiquewhite}, - {u"aquamarine", colors::aquamarine}, - {u"azure", colors::azure}, - {u"beige", colors::beige}, - {u"bisque", colors::bisque}, - {u"blanchedalmond", colors::blanchedalmond}, - {u"blueviolet", colors::blueviolet}, - {u"brown", colors::brown}, - {u"burlywood", colors::burlywood}, - {u"cadetblue", colors::cadetblue}, - {u"chartreuse", colors::chartreuse}, - {u"chocolate", colors::chocolate}, - {u"coral", colors::coral}, - {u"cornflowerblue", colors::cornflowerblue}, - {u"cornsilk", colors::cornsilk}, - {u"crimson", colors::crimson}, - {u"cyan", colors::cyan}, - {u"darkblue", colors::darkblue}, - {u"darkcyan", colors::darkcyan}, - {u"darkgoldenrod", colors::darkgoldenrod}, - {u"darkgray", colors::darkgray}, - {u"darkgreen", colors::darkgreen}, - {u"darkgrey", colors::darkgrey}, - {u"darkkhaki", colors::darkkhaki}, - {u"darkmagenta", colors::darkmagenta}, - {u"darkolivegreen", colors::darkolivegreen}, - {u"darkorange", colors::darkorange}, - {u"darkorchid", colors::darkorchid}, - {u"darkred", colors::darkred}, - {u"darksalmon", colors::darksalmon}, - {u"darkseagreen", colors::darkseagreen}, - {u"darkslateblue", colors::darkslateblue}, - {u"darkslategray", colors::darkslategray}, - {u"darkslategrey", colors::darkslategrey}, - {u"darkturquoise", colors::darkturquoise}, - {u"darkviolet", colors::darkviolet}, - {u"deeppink", colors::deeppink}, - {u"deepskyblue", colors::deepskyblue}, - {u"dimgray", colors::dimgray}, - {u"dimgrey", colors::dimgrey}, - {u"dodgerblue", colors::dodgerblue}, - {u"firebrick", colors::firebrick}, - {u"floralwhite", colors::floralwhite}, - {u"forestgreen", colors::forestgreen}, - {u"gainsboro", colors::gainsboro}, - {u"ghostwhite", colors::ghostwhite}, - {u"gold", colors::gold}, - {u"goldenrod", colors::goldenrod}, - {u"greenyellow", colors::greenyellow}, - {u"grey", colors::grey}, - {u"honeydew", colors::honeydew}, - {u"hotpink", colors::hotpink}, - {u"indianred", colors::indianred}, - {u"indigo", colors::indigo}, - {u"ivory", colors::ivory}, - {u"khaki", colors::khaki}, - {u"lavender", colors::lavender}, - {u"lavenderblush", colors::lavenderblush}, - {u"lawngreen", colors::lawngreen}, - {u"lemonchiffon", colors::lemonchiffon}, - {u"lightblue", colors::lightblue}, - {u"lightcoral", colors::lightcoral}, - {u"lightcyan", colors::lightcyan}, - {u"lightgoldenrodyellow", colors::lightgoldenrodyellow}, - {u"lightgray", colors::lightgray}, - {u"lightgreen", colors::lightgreen}, - {u"lightgrey", colors::lightgrey}, - {u"lightpink", colors::lightpink}, - {u"lightsalmon", colors::lightsalmon}, - {u"lightseagreen", colors::lightseagreen}, - {u"lightskyblue", colors::lightskyblue}, - {u"lightslategray", colors::lightslategray}, - {u"lightslategrey", colors::lightslategrey}, - {u"lightsteelblue", colors::lightsteelblue}, - {u"lightyellow", colors::lightyellow}, - {u"limegreen", colors::limegreen}, - {u"linen", colors::linen}, - {u"magenta", colors::magenta}, - {u"mediumaquamarine", colors::mediumaquamarine}, - {u"mediumblue", colors::mediumblue}, - {u"mediumorchid", colors::mediumorchid}, - {u"mediumpurple", colors::mediumpurple}, - {u"mediumseagreen", colors::mediumseagreen}, - {u"mediumslateblue", colors::mediumslateblue}, - {u"mediumspringgreen", colors::mediumspringgreen}, - {u"mediumturquoise", colors::mediumturquoise}, - {u"mediumvioletred", colors::mediumvioletred}, - {u"midnightblue", colors::midnightblue}, - {u"mintcream", colors::mintcream}, - {u"mistyrose", colors::mistyrose}, - {u"moccasin", colors::moccasin}, - {u"navajowhite", colors::navajowhite}, - {u"oldlace", colors::oldlace}, - {u"olivedrab", colors::olivedrab}, - {u"orangered", colors::orangered}, - {u"orchid", colors::orchid}, - {u"palegoldenrod", colors::palegoldenrod}, - {u"palegreen", colors::palegreen}, - {u"paleturquoise", colors::paleturquoise}, - {u"palevioletred", colors::palevioletred}, - {u"papayawhip", colors::papayawhip}, - {u"peachpuff", colors::peachpuff}, - {u"peru", colors::peru}, - {u"pink", colors::pink}, - {u"plum", colors::plum}, - {u"powderblue", colors::powderblue}, - {u"rosybrown", colors::rosybrown}, - {u"royalblue", colors::royalblue}, - {u"saddlebrown", colors::saddlebrown}, - {u"salmon", colors::salmon}, - {u"sandybrown", colors::sandybrown}, - {u"seagreen", colors::seagreen}, - {u"seashell", colors::seashell}, - {u"sienna", colors::sienna}, - {u"skyblue", colors::skyblue}, - {u"slateblue", colors::slateblue}, - {u"slategray", colors::slategray}, - {u"slategrey", colors::slategrey}, - {u"snow", colors::snow}, - {u"springgreen", colors::springgreen}, - {u"steelblue", colors::steelblue}, - {u"tan", colors::tan}, - {u"thistle", colors::thistle}, - {u"tomato", colors::tomato}, - {u"turquoise", colors::turquoise}, - {u"violet", colors::violet}, - {u"wheat", colors::wheat}, - {u"whitesmoke", colors::whitesmoke}, - {u"yellowgreen", colors::yellowgreen}, - {u"rebeccapurple", colors::rebeccapurple}, +namespace { +const std::unordered_map<std::string_view, Color> predefined_name_color_map{ + {"transparent", colors::transparent}, + {"black", colors::black}, + {"silver", colors::silver}, + {"gray", colors::gray}, + {"white", colors::white}, + {"maroon", colors::maroon}, + {"red", colors::red}, + {"purple", colors::purple}, + {"fuchsia", colors::fuchsia}, + {"green", colors::green}, + {"lime", colors::lime}, + {"olive", colors::olive}, + {"yellow", colors::yellow}, + {"navy", colors::navy}, + {"blue", colors::blue}, + {"teal", colors::teal}, + {"aqua", colors::aqua}, + {"orange", colors::orange}, + {"aliceblue", colors::aliceblue}, + {"antiquewhite", colors::antiquewhite}, + {"aquamarine", colors::aquamarine}, + {"azure", colors::azure}, + {"beige", colors::beige}, + {"bisque", colors::bisque}, + {"blanchedalmond", colors::blanchedalmond}, + {"blueviolet", colors::blueviolet}, + {"brown", colors::brown}, + {"burlywood", colors::burlywood}, + {"cadetblue", colors::cadetblue}, + {"chartreuse", colors::chartreuse}, + {"chocolate", colors::chocolate}, + {"coral", colors::coral}, + {"cornflowerblue", colors::cornflowerblue}, + {"cornsilk", colors::cornsilk}, + {"crimson", colors::crimson}, + {"cyan", colors::cyan}, + {"darkblue", colors::darkblue}, + {"darkcyan", colors::darkcyan}, + {"darkgoldenrod", colors::darkgoldenrod}, + {"darkgray", colors::darkgray}, + {"darkgreen", colors::darkgreen}, + {"darkgrey", colors::darkgrey}, + {"darkkhaki", colors::darkkhaki}, + {"darkmagenta", colors::darkmagenta}, + {"darkolivegreen", colors::darkolivegreen}, + {"darkorange", colors::darkorange}, + {"darkorchid", colors::darkorchid}, + {"darkred", colors::darkred}, + {"darksalmon", colors::darksalmon}, + {"darkseagreen", colors::darkseagreen}, + {"darkslateblue", colors::darkslateblue}, + {"darkslategray", colors::darkslategray}, + {"darkslategrey", colors::darkslategrey}, + {"darkturquoise", colors::darkturquoise}, + {"darkviolet", colors::darkviolet}, + {"deeppink", colors::deeppink}, + {"deepskyblue", colors::deepskyblue}, + {"dimgray", colors::dimgray}, + {"dimgrey", colors::dimgrey}, + {"dodgerblue", colors::dodgerblue}, + {"firebrick", colors::firebrick}, + {"floralwhite", colors::floralwhite}, + {"forestgreen", colors::forestgreen}, + {"gainsboro", colors::gainsboro}, + {"ghostwhite", colors::ghostwhite}, + {"gold", colors::gold}, + {"goldenrod", colors::goldenrod}, + {"greenyellow", colors::greenyellow}, + {"grey", colors::grey}, + {"honeydew", colors::honeydew}, + {"hotpink", colors::hotpink}, + {"indianred", colors::indianred}, + {"indigo", colors::indigo}, + {"ivory", colors::ivory}, + {"khaki", colors::khaki}, + {"lavender", colors::lavender}, + {"lavenderblush", colors::lavenderblush}, + {"lawngreen", colors::lawngreen}, + {"lemonchiffon", colors::lemonchiffon}, + {"lightblue", colors::lightblue}, + {"lightcoral", colors::lightcoral}, + {"lightcyan", colors::lightcyan}, + {"lightgoldenrodyellow", colors::lightgoldenrodyellow}, + {"lightgray", colors::lightgray}, + {"lightgreen", colors::lightgreen}, + {"lightgrey", colors::lightgrey}, + {"lightpink", colors::lightpink}, + {"lightsalmon", colors::lightsalmon}, + {"lightseagreen", colors::lightseagreen}, + {"lightskyblue", colors::lightskyblue}, + {"lightslategray", colors::lightslategray}, + {"lightslategrey", colors::lightslategrey}, + {"lightsteelblue", colors::lightsteelblue}, + {"lightyellow", colors::lightyellow}, + {"limegreen", colors::limegreen}, + {"linen", colors::linen}, + {"magenta", colors::magenta}, + {"mediumaquamarine", colors::mediumaquamarine}, + {"mediumblue", colors::mediumblue}, + {"mediumorchid", colors::mediumorchid}, + {"mediumpurple", colors::mediumpurple}, + {"mediumseagreen", colors::mediumseagreen}, + {"mediumslateblue", colors::mediumslateblue}, + {"mediumspringgreen", colors::mediumspringgreen}, + {"mediumturquoise", colors::mediumturquoise}, + {"mediumvioletred", colors::mediumvioletred}, + {"midnightblue", colors::midnightblue}, + {"mintcream", colors::mintcream}, + {"mistyrose", colors::mistyrose}, + {"moccasin", colors::moccasin}, + {"navajowhite", colors::navajowhite}, + {"oldlace", colors::oldlace}, + {"olivedrab", colors::olivedrab}, + {"orangered", colors::orangered}, + {"orchid", colors::orchid}, + {"palegoldenrod", colors::palegoldenrod}, + {"palegreen", colors::palegreen}, + {"paleturquoise", colors::paleturquoise}, + {"palevioletred", colors::palevioletred}, + {"papayawhip", colors::papayawhip}, + {"peachpuff", colors::peachpuff}, + {"peru", colors::peru}, + {"pink", colors::pink}, + {"plum", colors::plum}, + {"powderblue", colors::powderblue}, + {"rosybrown", colors::rosybrown}, + {"royalblue", colors::royalblue}, + {"saddlebrown", colors::saddlebrown}, + {"salmon", colors::salmon}, + {"sandybrown", colors::sandybrown}, + {"seagreen", colors::seagreen}, + {"seashell", colors::seashell}, + {"sienna", colors::sienna}, + {"skyblue", colors::skyblue}, + {"slateblue", colors::slateblue}, + {"slategray", colors::slategray}, + {"slategrey", colors::slategrey}, + {"snow", colors::snow}, + {"springgreen", colors::springgreen}, + {"steelblue", colors::steelblue}, + {"tan", colors::tan}, + {"thistle", colors::thistle}, + {"tomato", colors::tomato}, + {"turquoise", colors::turquoise}, + {"violet", colors::violet}, + {"wheat", colors::wheat}, + {"whitesmoke", colors::whitesmoke}, + {"yellowgreen", colors::yellowgreen}, + {"rebeccapurple", colors::rebeccapurple}, }; -} // namespace details +} // namespace -std::optional<Color> GetPredefinedColorByName(StringView name) { - auto result = details::predefined_name_color_map.find(name); - if (result != details::predefined_name_color_map.cend()) { +std::optional<Color> GetPredefinedColorByName(std::string_view name) { + auto result = predefined_name_color_map.find(name); + if (result != predefined_name_color_map.cend()) { return result->second; } else { return std::nullopt; diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp index a959e6d8..dcf3a522 100644 --- a/src/ui/mapper/ColorMapper.cpp +++ b/src/ui/mapper/ColorMapper.cpp @@ -6,7 +6,7 @@ bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { } Color ColorMapper::DoMapFromString(std::string str) { - auto c = Color::Parse(String::FromUtf8(str)); + auto c = Color::Parse(str); if (!c) { throw Exception("Invalid color value."); } diff --git a/test/platform/ColorTest.cpp b/test/platform/ColorTest.cpp index 0c7c18ba..128c873a 100644 --- a/test/platform/ColorTest.cpp +++ b/test/platform/ColorTest.cpp @@ -5,10 +5,10 @@ using cru::platform::Color; TEST_CASE("Color Parse", "[color]") { - REQUIRE(Color::Parse(u"blue") == Color::Parse(u"#0000ff")); - REQUIRE(Color::Parse(u"#12abAB") == Color::FromHex(0x12abAB)); - REQUIRE(Color::Parse(u"#8812abAB") == Color::FromHexAlpha(0x8812abAB)); - REQUIRE(Color::Parse(u"averystrangestring") == std::nullopt); - REQUIRE(Color::Parse(u"112233") == std::nullopt); - REQUIRE(Color::Parse(u"#7777777") == std::nullopt); + REQUIRE(Color::Parse("blue") == Color::Parse("#0000ff")); + REQUIRE(Color::Parse("#12abAB") == Color::FromHex(0x12abAB)); + REQUIRE(Color::Parse("#8812abAB") == Color::FromHexAlpha(0x8812abAB)); + REQUIRE(Color::Parse("averystrangestring") == std::nullopt); + REQUIRE(Color::Parse("112233") == std::nullopt); + REQUIRE(Color::Parse("#7777777") == std::nullopt); } |