Skip to content

Commit

Permalink
Changed enumFromString to be case insensitive. Needed because sometim…
Browse files Browse the repository at this point in the history
…e lenth units are 'Meter' and sometimes 'meter'.
  • Loading branch information
StephenCzarnecki committed Dec 19, 2024
1 parent 61e869f commit 4d40f00
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion include/fileParse/StringConversion.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ namespace FileParse
return from_string<T>(str);
}

inline std::string toLower(std::string s)
{
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4244)
#endif
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
#ifdef _MSC_VER
# pragma warning(pop)
#endif
return s;
}

/// Enumerator to string conversion routines.

/// Converts an enumerator value to a string.
Expand All @@ -77,9 +90,10 @@ namespace FileParse
const std::array<std::string, N> & values,
EnumType defaultValue)
{
auto nameLower = toLower(std::string(name));
for(std::size_t i = 0; i < values.size(); ++i)
{
if(values[i] == name)
if(toLower(values[i]) == nameLower)
{
return static_cast<EnumType>(i);
}
Expand Down

0 comments on commit 4d40f00

Please sign in to comment.