Skip to content

Instantly share code, notes, and snippets.

@TurtleShip
Last active April 7, 2019 07:45
Show Gist options
  • Save TurtleShip/22041177fd36f6d57b01feb10e2e8925 to your computer and use it in GitHub Desktop.
Save TurtleShip/22041177fd36f6d57b01feb10e2e8925 to your computer and use it in GitHub Desktop.
void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
{
if (userPreferences.empty())
{
return;
}
vector<wstring> outerTokens = StringToVector(userPreferences, L"|");
if (outerTokens.size() == 3)
{
auto fromType = StringToUnit(outerTokens[0]);
auto toType = StringToUnit(outerTokens[1]);
m_currentCategory = StringToCategory(outerTokens[2]);
// Only restore from the saved units if they are valid in the current available units.
auto itr = m_categoryToUnits.find(m_currentCategory);
if (itr != m_categoryToUnits.end())
{
auto curUnits = itr->second;
if (find(curUnits.begin(), curUnits.end(), fromType) != curUnits.end())
{
m_fromType = fromType;
}
if (find(curUnits.begin(), curUnits.end(), fromType) != curUnits.end())
{
m_toType = toType;
}
}
}
}
@rudyhuyn
Copy link

rudyhuyn commented Apr 7, 2019

line 25:
if (find(curUnits.begin(), curUnits.end(), toType) != curUnits.end())

@rudyhuyn
Copy link

rudyhuyn commented Apr 7, 2019

NIT:
if (outerTokens.size() != 3)
{
return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment