Better handling of out of bound enum values in ToString.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
60802341b0
commit
9244249a64
|
@ -61,7 +61,11 @@
|
||||||
public: \
|
public: \
|
||||||
constexpr static const char* ToString(name value) { \
|
constexpr static const char* ToString(name value) { \
|
||||||
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \
|
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \
|
||||||
throw std::logic_error("Not reachable"); \
|
auto v = static_cast<int>(value); \
|
||||||
|
auto size = (int)((ceil(log10(v)) + 1) * sizeof(char)); \
|
||||||
|
char* snum = new char[size]; \
|
||||||
|
sprintf(snum, "%d", v); \
|
||||||
|
return snum; \
|
||||||
} \
|
} \
|
||||||
constexpr static name Parse(const char* input, bool caseInsensitive = false) { \
|
constexpr static name Parse(const char* input, bool caseInsensitive = false) { \
|
||||||
if (caseInsensitive) \
|
if (caseInsensitive) \
|
||||||
|
|
|
@ -56,6 +56,7 @@ TEST_CASE("Enum To String", "[Utilities]") {
|
||||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val1), "Val1") == 0);
|
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val1), "Val1") == 0);
|
||||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val2), "Val2") == 0);
|
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val2), "Val2") == 0);
|
||||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val3), "Val3") == 0);
|
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val3), "Val3") == 0);
|
||||||
|
CHECK(strcmp(TestEnumHelper::ToString((TestEnum)100), "100") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Enum Get Values", "[Utilities]") {
|
TEST_CASE("Enum Get Values", "[Utilities]") {
|
||||||
|
|
Loading…
Reference in New Issue