@@ -70,14 +70,17 @@ Duration parse_duration(std::string_view input) {
7070
7171 std::chrono::nanoseconds total_duration{0 };
7272
73- for (auto i = begin; i != end; ++i) {
74- auto match = *i;
75- auto number_str = match[1 ];
76- auto unit_str = match[2 ];
73+ for (auto match = begin; match != end; ++match) {
74+ if (match->size () != 3 ) {
75+ throw RuntimeError (" Invalid duration format: {}" , match->str ());
76+ }
77+
78+ auto number_str = match->str (1 );
79+ auto unit_str = match->str (2 );
7780
7881 auto it = unit_map.find (unit_str);
7982 if (it == unit_map.end ()) {
80- throw RuntimeError (" Unknown duration unit: {}" , unit_str. str () );
83+ throw RuntimeError (" Unknown duration unit: {}" , unit_str);
8184 }
8285
8386 auto unit = it->second ;
@@ -86,10 +89,10 @@ Duration parse_duration(std::string_view input) {
8689 try {
8790 number = std::stoul (number_str);
8891 } catch (const std::invalid_argument &e) {
89- throw RuntimeError (" Invalid number in duration: {}" , match. str ());
92+ throw RuntimeError (" Invalid number in duration: {}" , match-> str ());
9093 } catch (const std::out_of_range &e) {
9194 throw RuntimeError (" Duration overflows maximum representable value: {}" ,
92- match. str ());
95+ match-> str ());
9396 }
9497
9598 auto duration = unit * number;
@@ -100,8 +103,7 @@ Duration parse_duration(std::string_view input) {
100103 if (unit.count () != 0 &&
101104 duration.count () / unit.count () != number) // Check for overflow.
102105 throw RuntimeError (" Duration overflows maximum representable value: {}" ,
103- match.str ());
104- ;
106+ match->str ());
105107
106108 total_duration += duration;
107109 }
0 commit comments