diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-06-04 01:07:18 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-06-04 01:07:18 +0100 |
commit | 301fe23825759bbb4602776483554f6cf95cb8a6 (patch) | |
tree | c3efb6b1faa1af0a79c0569bcfe1922800f955d7 /assetFactory/assetFactory.cpp | |
parent | Avoid pointer arithmetic AssetFactory::parseColour (diff) | |
download | ilt-301fe23825759bbb4602776483554f6cf95cb8a6.tar.bz2 ilt-301fe23825759bbb4602776483554f6cf95cb8a6.tar.xz ilt-301fe23825759bbb4602776483554f6cf95cb8a6.zip |
Remove fscanf and fixed buffers from AssetFactory::parseX11RGB
Diffstat (limited to 'assetFactory/assetFactory.cpp')
-rw-r--r-- | assetFactory/assetFactory.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index db31ca8..fe4e0be 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -11,6 +11,7 @@ #include "resource.h" #include "saxParse-persistence.h" #include "texturePacker.h" +#include <fstream> #include <numeric> AssetFactory::AssetFactory() : @@ -45,14 +46,17 @@ AssetFactory::loadAll(const std::filesystem::path & root) AssetFactory::Colours AssetFactory::parseX11RGB(const char * path) { - filesystem::FileStar rgb {path, "r"}; + std::ifstream rgb {path}; Colours out; - Colour colour; - char inname[BUFSIZ]; - while (fscanf(rgb, "%f %f %f %[^\n\r]s", &colour.r, &colour.g, &colour.b, inname) == 4) { - std::string name {inname}; - normalizeColourName(name); - out.emplace(std::move(name), colour / 255.f); + while (rgb.good()) { + Colour colour; + std::string name; + rgb >> colour.r >> colour.g >> colour.b; + std::getline(rgb, name); + if (rgb.good()) { + normalizeColourName(name); + out.emplace(std::move(name), colour / 255.F); + } } return out; } |