Added more checks for colors.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
024fd4eb79
commit
4201830e43
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
project(identiconpp
|
project(identiconpp
|
||||||
VERSION 0.1.0
|
VERSION 0.1.1
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <iomanip>
|
#include <algorithm>
|
||||||
#include "identiconpp.hpp"
|
#include "identiconpp.hpp"
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
|
||||||
|
@ -32,21 +32,11 @@ Identiconpp::Identiconpp(const uint8_t rows, const uint8_t columns,
|
||||||
, _background(background)
|
, _background(background)
|
||||||
, _foreground(foreground)
|
, _foreground(foreground)
|
||||||
{
|
{
|
||||||
if (background.length() != 8)
|
check_color(background);
|
||||||
{
|
|
||||||
throw std::invalid_argument
|
|
||||||
(
|
|
||||||
"The background color must consist of exactly 8 digits."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const string &color : foreground)
|
for (const string &color : foreground)
|
||||||
if (color.length() != 8)
|
|
||||||
{
|
{
|
||||||
throw std::invalid_argument
|
check_color(color);
|
||||||
(
|
|
||||||
"The foreground colors must consist of exactly 8 digits."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,3 +184,35 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
|
||||||
ttdebug << "Color: #" << _foreground[bits - 1] << '\n';
|
ttdebug << "Color: #" << _foreground[bits - 1] << '\n';
|
||||||
return Magick::Color("#" + _foreground[bits - 1]);
|
return Magick::Color("#" + _foreground[bits - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Identiconpp::not_hex(const char c)
|
||||||
|
{
|
||||||
|
if (c >= 0x61 && c <= 0x66)
|
||||||
|
{ // a-f
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (c >= 0x30 && c <= 0x39)
|
||||||
|
{ // 0-9
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Identiconpp::check_color(const string &color)
|
||||||
|
{
|
||||||
|
if (color.length() != 8)
|
||||||
|
{
|
||||||
|
throw std::invalid_argument
|
||||||
|
(
|
||||||
|
"Colors must consist of exactly 8 digits(" + color + ")."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (std::any_of(color.begin(), color.end(), not_hex))
|
||||||
|
{
|
||||||
|
throw std::invalid_argument
|
||||||
|
(
|
||||||
|
"Colors must consist of hexadecimal digits (" + color + ")."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
* @param foreground vector of foreground colors
|
* @param foreground vector of foreground colors
|
||||||
*/
|
*/
|
||||||
explicit Identiconpp(const uint8_t rows, const uint8_t columns,
|
explicit Identiconpp(const uint8_t rows, const uint8_t columns,
|
||||||
identicon_type type,
|
identicon_type type = identicon_type::simple,
|
||||||
const string background = "ffffffff",
|
const string background = "ffffffff",
|
||||||
const vector<string> &foreground = { "000000ff" } );
|
const vector<string> &foreground = { "000000ff" } );
|
||||||
|
|
||||||
|
@ -139,4 +139,20 @@ private:
|
||||||
* @return A foreground color.
|
* @return A foreground color.
|
||||||
*/
|
*/
|
||||||
Magick::Color get_color(const uint16_t firstbit, const string &digest);
|
Magick::Color get_color(const uint16_t firstbit, const string &digest);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Checks if character is not hexadecimal.
|
||||||
|
*
|
||||||
|
* @param c Character to check
|
||||||
|
*
|
||||||
|
* @return true if not hex.
|
||||||
|
*/
|
||||||
|
static bool not_hex(const char c);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Performs checks on a color definition in a string.
|
||||||
|
*
|
||||||
|
* @param color The color as string
|
||||||
|
*/
|
||||||
|
void check_color(const string &color);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue