moved to regex in parse time from line
This commit is contained in:
@@ -31,17 +31,24 @@ bool parse_date_from_filename(std::string_view path,
|
||||
bool parse_time_from_line(std::string_view line,
|
||||
int& hour, int& min, int& sec)
|
||||
{
|
||||
// Expect: [HH:MM:SS]
|
||||
if (line.size() < 10 || line[0] != '[')
|
||||
// Match [HH:MM:SS] anywhere in the line
|
||||
static const std::regex re(
|
||||
R"(\[(\d{2}):(\d{2}):(\d{2})\])",
|
||||
std::regex::optimize
|
||||
);
|
||||
|
||||
std::cmatch m;
|
||||
if (!std::regex_search(line.begin(), line.end(), m, re))
|
||||
return false;
|
||||
|
||||
hour = (line[1] - '0') * 10 + (line[2] - '0');
|
||||
min = (line[4] - '0') * 10 + (line[5] - '0');
|
||||
sec = (line[7] - '0') * 10 + (line[8] - '0');
|
||||
hour = (m[1].str()[0] - '0') * 10 + (m[1].str()[1] - '0');
|
||||
min = (m[2].str()[0] - '0') * 10 + (m[2].str()[1] - '0');
|
||||
sec = (m[3].str()[0] - '0') * 10 + (m[3].str()[1] - '0');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#include <ctime>
|
||||
#include <string_view>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user