summaryrefslogtreecommitdiff
path: root/assetFactory/assetFactory.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-06-03 23:46:59 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-06-03 23:47:02 +0100
commit09a8433caae419e9ef87a770197ee893123ae978 (patch)
treea4c9538e1c266bd6863029877017111c5616c0f7 /assetFactory/assetFactory.cpp
parentDisable -Wenum-constexpr-conversion in parts of enumDetails.h (diff)
downloadilt-09a8433caae419e9ef87a770197ee893123ae978.tar.bz2
ilt-09a8433caae419e9ef87a770197ee893123ae978.tar.xz
ilt-09a8433caae419e9ef87a770197ee893123ae978.zip
Avoid pointer arithmetic AssetFactory::parseColour
Diffstat (limited to 'assetFactory/assetFactory.cpp')
-rw-r--r--assetFactory/assetFactory.cpp11
1 files 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<float>(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<float>(channel) / 255.F;
});
return out;
}