Refactor color validator from settings to utility source

This commit is contained in:
Dan Paulat 2024-09-19 23:15:41 -05:00
parent 8fc392681a
commit c8dc8ed630
3 changed files with 18 additions and 11 deletions

View file

@ -1,6 +1,7 @@
#include <scwx/qt/util/color.hpp>
#include <fmt/format.h>
#include <re2/re2.h>
#include <QColor>
namespace scwx
@ -38,6 +39,12 @@ boost::gil::rgba32f_pixel_t ToRgba32fPixelT(const std::string& argbString)
rgba8Pixel[3] / 255.0f};
}
bool ValidateArgbString(const std::string& argbString)
{
static constexpr LazyRE2 re = {"#[0-9A-Fa-f]{8}"};
return RE2::FullMatch(argbString, *re);
}
} // namespace color
} // namespace util
} // namespace qt

View file

@ -39,6 +39,15 @@ boost::gil::rgba8_pixel_t ToRgba8PixelT(const std::string& argbString);
*/
boost::gil::rgba32f_pixel_t ToRgba32fPixelT(const std::string& argbString);
/**
* Validates an ARGB string used by Qt libraries.
*
* @param argbString
*
* @return Validity of ARGB string
*/
bool ValidateArgbString(const std::string& argbString);
} // namespace color
} // namespace util
} // namespace qt