Move log service file parsing to use from_chars
std::from_chars seems to be what most other bmcweb code has moved to,
and allows removal of exceptions usage.
Tested:
Ran redfishtool -S Always -A Session -u root -p 0penBmc -r 192.168.7.2 raw GET "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/1632252609998258"
And observed that the uri component got parsed properly.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Icd4808196eeae0f8a19a208a065b5f2f4f0b050c
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 6ddd6d6..3b9069f 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -332,44 +332,18 @@
tsStr.remove_suffix(tsStr.size() - underscorePos);
std::string_view indexStr(entryID);
indexStr.remove_prefix(underscorePos + 1);
- std::size_t pos;
- try
- {
- index = std::stoul(std::string(indexStr), &pos);
- }
- catch (std::invalid_argument&)
- {
- messages::resourceMissingAtURI(asyncResp->res, entryID);
- return false;
- }
- catch (std::out_of_range&)
- {
- messages::resourceMissingAtURI(asyncResp->res, entryID);
- return false;
- }
- if (pos != indexStr.size())
+ auto [ptr, ec] = std::from_chars(
+ indexStr.data(), indexStr.data() + indexStr.size(), index);
+ if (ec != std::errc())
{
messages::resourceMissingAtURI(asyncResp->res, entryID);
return false;
}
}
// Timestamp has no index
- std::size_t pos;
- try
- {
- timestamp = std::stoull(std::string(tsStr), &pos);
- }
- catch (std::invalid_argument&)
- {
- messages::resourceMissingAtURI(asyncResp->res, entryID);
- return false;
- }
- catch (std::out_of_range&)
- {
- messages::resourceMissingAtURI(asyncResp->res, entryID);
- return false;
- }
- if (pos != tsStr.size())
+ auto [ptr, ec] =
+ std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp);
+ if (ec != std::errc())
{
messages::resourceMissingAtURI(asyncResp->res, entryID);
return false;