1010#include < perfcpp/time_event.h>
1111#include < regex>
1212#include < sstream>
13+ #include < cctype>
1314
1415void
1516perf::PerfSubsystemEventProvider::add_events (perf::CounterDefinition& counter_definition)
@@ -331,18 +332,21 @@ perf::SystemSpecificEventProvider::parse_event_file_descriptor_format(std::files
331332std::optional<std::uint64_t >
332333perf::SystemSpecificEventProvider::parse_integer (const std::string& value)
333334{
334- if (value.empty ()) {
335+ std::string copied_str = value;
336+ copied_str.erase (std::remove_if (copied_str.begin (), copied_str.end (), [](unsigned char c){return std::isspace (c);}), copied_str.end ());
337+
338+ if (copied_str.empty ()) {
335339 return std::nullopt ;
336340 }
337341
338342 // / Strings starting with '0x' are considered hex numbers.
339- if (value .rfind (" 0x" , 0ULL ) == 0ULL ) {
340- return std::stoull (value .substr (2ULL ), nullptr , 16 );
343+ if (copied_str .rfind (" 0x" , 0ULL ) == 0ULL ) {
344+ return std::stoull (copied_str .substr (2ULL ), nullptr , 16 );
341345 }
342346
343347 // / Strings containing digits are considered dec numbers.
344- if (std::all_of (value .begin (), value .end (), [](const auto c) { return std::isdigit (c); })) {
345- return std::stoull (value , nullptr , 0 );
348+ if (std::all_of (copied_str .begin (), copied_str .end (), [](const auto c) { return std::isdigit (c); })) {
349+ return std::stoull (copied_str , nullptr , 0 );
346350 }
347351
348352 return std::nullopt ;
@@ -482,7 +486,7 @@ perf::CsvFileEventProvider::add_events(perf::CounterDefinition& counter_definiti
482486 auto line_stream = std::istringstream{ line };
483487
484488 std::string name;
485-
489+
486490 // / Read name.
487491 if (std::getline (line_stream, name, ' ,' ); !name.empty ()) {
488492
@@ -522,4 +526,4 @@ perf::CsvFileEventProvider::add_events(perf::CounterDefinition& counter_definiti
522526 }
523527 }
524528 }
525- }
529+ }
0 commit comments