From 0201f22237d7ad64a33c5acd46b2398ee51babf0 Mon Sep 17 00:00:00 2001 From: Aaron Bishop Date: Thu, 2 Nov 2017 17:04:28 -0400 Subject: [PATCH 1/2] fix const correctness error --- source/detail/serialization/miniz.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/detail/serialization/miniz.cpp b/source/detail/serialization/miniz.cpp index 290ff88e..f6bf2335 100644 --- a/source/detail/serialization/miniz.cpp +++ b/source/detail/serialization/miniz.cpp @@ -2095,7 +2095,7 @@ void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int for (y = 0; y < h; ++y) { tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); - tdefl_compress_buffer(pComp, (mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); + tdefl_compress_buffer(pComp, (const mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); } if (tdefl_compress_buffer(pComp, nullptr, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) { From b008eacd89961c587aef2540462f8d22113c088f Mon Sep 17 00:00:00 2001 From: tal Date: Sat, 18 Nov 2017 22:26:30 -0700 Subject: [PATCH 2/2] custom_value_traits.hpp: pattern_fill from_string() ignores case Values like lightGray will match with lightgray. Unexpected inputs will be ignored and return none. Needs prama to clang to be happy. --- .../serialization/custom_value_traits.hpp | 68 +++++++++++++------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/source/detail/serialization/custom_value_traits.hpp b/source/detail/serialization/custom_value_traits.hpp index a5ac3003..576718b5 100644 --- a/source/detail/serialization/custom_value_traits.hpp +++ b/source/detail/serialization/custom_value_traits.hpp @@ -23,7 +23,9 @@ #pragma once +#include #include +#include #include #include @@ -168,27 +170,53 @@ relationship_type from_string(const std::string &string) template<> pattern_fill_type from_string(const std::string &string) { - if (string == "darkdown") return pattern_fill_type::darkdown; - else if (string == "darkgray") return pattern_fill_type::darkgray; - else if (string == "darkgrid") return pattern_fill_type::darkgrid; - else if (string == "darkhorizontal") return pattern_fill_type::darkhorizontal; - else if (string == "darktrellis") return pattern_fill_type::darktrellis; - else if (string == "darkup") return pattern_fill_type::darkup; - else if (string == "darkvertical") return pattern_fill_type::darkvertical; - else if (string == "gray0625") return pattern_fill_type::gray0625; - else if (string == "gray125") return pattern_fill_type::gray125; - else if (string == "lightdown") return pattern_fill_type::lightdown; - else if (string == "lightgray") return pattern_fill_type::lightgray; - else if (string == "lightgrid") return pattern_fill_type::lightgrid; - else if (string == "lighthorizontal") return pattern_fill_type::lighthorizontal; - else if (string == "lighttrellis") return pattern_fill_type::lighttrellis; - else if (string == "lightup") return pattern_fill_type::lightup; - else if (string == "lightvertical") return pattern_fill_type::lightvertical; - else if (string == "mediumgray") return pattern_fill_type::mediumgray; - else if (string == "none") return pattern_fill_type::none; - else if (string == "solid") return pattern_fill_type::solid; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wexit-time-destructors" + static std::unordered_map patternFill { + {"darkdown", pattern_fill_type::darkdown }, + { "darkgray", pattern_fill_type::darkgray }, + { "darkgrid", pattern_fill_type::darkgrid }, + { "darkhorizontal", pattern_fill_type::darkhorizontal }, + { "darktrellis", pattern_fill_type::darktrellis }, + { "darkup", pattern_fill_type::darkup }, + { "darkvertical", pattern_fill_type::darkvertical }, + { "gray0625", pattern_fill_type::gray0625 }, + { "gray125", pattern_fill_type::gray125 }, + { "lightdown", pattern_fill_type::lightdown }, + { "lightgray", pattern_fill_type::lightgray }, + { "lightgrid", pattern_fill_type::lightgrid }, + { "lighthorizontal", pattern_fill_type::lighthorizontal }, + { "lighttrellis", pattern_fill_type::lighttrellis }, + { "lightup", pattern_fill_type::lightup }, + { "lightvertical", pattern_fill_type::lightvertical }, + { "mediumgray", pattern_fill_type::mediumgray }, + { "none", pattern_fill_type::none }, + { "solid", pattern_fill_type::solid } + }; +#pragma clang diagnostic pop + + auto toLower = [](std::string str) { + auto bg{ std::begin (str) }; + auto en{ std::end (str) }; + std::transform (bg, en, bg, tolower); - default_case(pattern_fill_type::none); + return str; + }; + + auto patternLookup = [](const std::string& key) { + auto entry { patternFill.find (key) }; + if (entry != std::end (patternFill)) { + return entry->second; + } + else { + // Note: there won't be an error if there is an unsupported pattern + return pattern_fill_type::none; + } + }; + + std::string lowerString {toLower (string) }; + + return patternLookup (lowerString); } template<>