From 09a8433caae419e9ef87a770197ee893123ae978 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 3 Jun 2024 23:46:59 +0100 Subject: Avoid pointer arithmetic AssetFactory::parseColour --- assetFactory/assetFactory.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index 218c4e7..db31ca8 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -77,11 +77,12 @@ AssetFactory::parseColour(std::string_view in) const throw std::runtime_error("Invalid hex colour specification"); } ColourAlpha out {0, 0, 0, 1}; - std::generate_n(&out.r, (in.length() - 1) / 2, [in = in.data() + 1]() mutable { - uint8_t channel; - std::from_chars(in, in + 2, channel, 16); - in += 2; - return static_cast(channel) / 255.f; + std::generate_n(&out.r, (in.length() - 1) / 2, [in = in.substr(1)]() mutable { + const auto hexpair = in.substr(0, 2); + uint8_t channel = 0; + std::from_chars(hexpair.begin(), hexpair.end(), channel, 16); + in.remove_prefix(2); + return static_cast(channel) / 255.F; }); return out; } -- cgit v1.2.3