Skip to content

Commit

Permalink
Another occurrence of from_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Jan 3, 2024
1 parent ad36401 commit 560605c
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions hardware_interface/src/component_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,23 @@ double get_parameter_value_or(
{
while (params_it)
{
// Fill the map with parameters
const auto tag_name = params_it->Name();
if (strcmp(tag_name, parameter_name) == 0)
try
{
const auto tag_text = params_it->GetText();
if (tag_text)
// Fill the map with parameters
const auto tag_name = params_it->Name();
if (strcmp(tag_name, parameter_name) == 0)
{
// Parse and return double value if there is no parsing error
double result_value;
const auto parse_result =
std::from_chars(tag_text, tag_text + std::strlen(tag_text), result_value);
if (parse_result.ec == std::errc())
const auto tag_text = params_it->GetText();
if (tag_text)
{
return result_value;
return hardware_interface::stod(tag_text);
}

// Parsing failed - exit loop and return default value
break;
}
}
catch (const std::exception & e)
{
return default_value;
}

params_it = params_it->NextSiblingElement();
}
Expand Down

0 comments on commit 560605c

Please sign in to comment.