summaryrefslogtreecommitdiff
path: root/src/csscolorparser/csscolorparser.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/csscolorparser/csscolorparser.hpp')
-rw-r--r--src/csscolorparser/csscolorparser.hpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/csscolorparser/csscolorparser.hpp b/src/csscolorparser/csscolorparser.hpp
index 6caf796943..c0ef767f0e 100644
--- a/src/csscolorparser/csscolorparser.hpp
+++ b/src/csscolorparser/csscolorparser.hpp
@@ -1,5 +1,5 @@
// (c) Dean McNamee <dean@gmail.com>, 2012.
-// C++ port by Konstantin Käfer <mail@kkaefer.com>, 2014.
+// C++ port by Mapbox, Konstantin Käfer <mail@kkaefer.com>, 2014-2017.
//
// https://github.com/deanm/css-color-parser-js
// https://github.com/kkaefer/css-color-parser-cpp
@@ -26,19 +26,30 @@
#define CSS_COLOR_PARSER_CPP
#include <string>
+#include <cmath>
namespace CSSColorParser {
struct Color {
- inline Color() {}
+ inline Color() {
+ }
inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_)
- : r(r_), g(g_), b(b_), a(a_) {}
+ : r(r_), g(g_), b(b_), a(a_ > 1 ? 1 : a_ < 0 ? 0 : a_) {
+ }
unsigned char r = 0, g = 0, b = 0;
float a = 1.0f;
};
-Color parse(const std::string& css_str);
+inline bool operator==(const Color& lhs, const Color& rhs) {
+ return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && ::fabs(lhs.a - lhs.b) < 0.0001f;
+}
+inline bool operator!=(const Color& lhs, const Color& rhs) {
+ return !(lhs == rhs);
}
+Color parse(const std::string& css_str);
+
+} // namespace CSSColorParser
+
#endif