Merge pull request #248 from tlanc007/cellPropertyColors

custom_value_traits.hpp: pattern_fill from_string() ignores case
This commit is contained in:
Thomas Fussell 2017-12-08 14:37:24 -05:00 committed by GitHub
commit 20c7d3437c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,9 @@
#pragma once #pragma once
#include <algorithm>
#include <string> #include <string>
#include <unordered_map>
#include <detail/default_case.hpp> #include <detail/default_case.hpp>
#include <detail/external/include_libstudxml.hpp> #include <detail/external/include_libstudxml.hpp>
@ -168,27 +170,53 @@ relationship_type from_string(const std::string &string)
template<> template<>
pattern_fill_type from_string(const std::string &string) pattern_fill_type from_string(const std::string &string)
{ {
if (string == "darkdown") return pattern_fill_type::darkdown; #pragma clang diagnostic push
else if (string == "darkgray") return pattern_fill_type::darkgray; #pragma clang diagnostic ignored "-Wexit-time-destructors"
else if (string == "darkgrid") return pattern_fill_type::darkgrid; static std::unordered_map<std::string, pattern_fill_type> patternFill {
else if (string == "darkhorizontal") return pattern_fill_type::darkhorizontal; {"darkdown", pattern_fill_type::darkdown },
else if (string == "darktrellis") return pattern_fill_type::darktrellis; { "darkgray", pattern_fill_type::darkgray },
else if (string == "darkup") return pattern_fill_type::darkup; { "darkgrid", pattern_fill_type::darkgrid },
else if (string == "darkvertical") return pattern_fill_type::darkvertical; { "darkhorizontal", pattern_fill_type::darkhorizontal },
else if (string == "gray0625") return pattern_fill_type::gray0625; { "darktrellis", pattern_fill_type::darktrellis },
else if (string == "gray125") return pattern_fill_type::gray125; { "darkup", pattern_fill_type::darkup },
else if (string == "lightdown") return pattern_fill_type::lightdown; { "darkvertical", pattern_fill_type::darkvertical },
else if (string == "lightgray") return pattern_fill_type::lightgray; { "gray0625", pattern_fill_type::gray0625 },
else if (string == "lightgrid") return pattern_fill_type::lightgrid; { "gray125", pattern_fill_type::gray125 },
else if (string == "lighthorizontal") return pattern_fill_type::lighthorizontal; { "lightdown", pattern_fill_type::lightdown },
else if (string == "lighttrellis") return pattern_fill_type::lighttrellis; { "lightgray", pattern_fill_type::lightgray },
else if (string == "lightup") return pattern_fill_type::lightup; { "lightgrid", pattern_fill_type::lightgrid },
else if (string == "lightvertical") return pattern_fill_type::lightvertical; { "lighthorizontal", pattern_fill_type::lighthorizontal },
else if (string == "mediumgray") return pattern_fill_type::mediumgray; { "lighttrellis", pattern_fill_type::lighttrellis },
else if (string == "none") return pattern_fill_type::none; { "lightup", pattern_fill_type::lightup },
else if (string == "solid") return pattern_fill_type::solid; { "lightvertical", pattern_fill_type::lightvertical },
{ "mediumgray", pattern_fill_type::mediumgray },
{ "none", pattern_fill_type::none },
{ "solid", pattern_fill_type::solid }
};
#pragma clang diagnostic pop
default_case(pattern_fill_type::none); auto toLower = [](std::string str) {
auto bg{ std::begin (str) };
auto en{ std::end (str) };
std::transform (bg, en, bg, tolower);
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<> template<>