Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gibber9809 committed Dec 13, 2024
1 parent dd1539d commit 22e5ad4
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions components/core/src/clp_s/TimestampPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using clp::string_utils::convert_string_to_int;
using std::string;
using std::string_view;
using std::to_string;
using std::vector;

Expand Down Expand Up @@ -73,7 +74,7 @@ append_padded_value_notz(int value, char padding_character, size_t max_length, s
* @return true if conversion succeeds, false otherwise
*/
static bool convert_string_to_number(
std::string_view str,
string_view str,
size_t begin_ix,
size_t end_ix,
char padding_character,
Expand All @@ -91,7 +92,7 @@ static bool convert_string_to_number(
* @return true if conversion succeeds, false otherwise
*/
static bool convert_string_to_number_notz(
std::string_view str,
string_view str,
size_t max_digits,
size_t begin_ix,
size_t& end_ix,
Expand Down Expand Up @@ -127,7 +128,7 @@ append_padded_value_notz(int value, char padding_character, size_t max_length, s
}

static bool convert_string_to_number(
std::string_view str,
string_view str,
size_t begin_ix,
size_t end_ix,
char padding_character,
Expand Down Expand Up @@ -156,7 +157,7 @@ static bool convert_string_to_number(
}

static bool convert_string_to_number_notz(
std::string_view str,
string_view str,
size_t max_digits,
size_t begin_ix,
size_t& end_ix,
Expand Down Expand Up @@ -308,7 +309,7 @@ void TimestampPattern::init() {
}

TimestampPattern const* TimestampPattern::search_known_ts_patterns(
std::string_view line,
string_view line,
epochtime_t& timestamp,
size_t& timestamp_begin_pos,
size_t& timestamp_end_pos
Expand Down Expand Up @@ -344,7 +345,7 @@ void TimestampPattern::clear() {
}

bool TimestampPattern::parse_timestamp(
std::string_view line,
string_view line,
epochtime_t& timestamp,
size_t& timestamp_begin_pos,
size_t& timestamp_end_pos
Expand Down Expand Up @@ -829,23 +830,20 @@ bool TimestampPattern::parse_timestamp(
}
auto dot_position = line.find('.');
auto nanosecond_start = dot_position + 1;
if (std::string::npos == dot_position || 0 == dot_position
if (string::npos == dot_position || 0 == dot_position
|| cNanosecondDigits != (line.length() - nanosecond_start))
{
return false;
}

auto timestamp_view = std::string_view(line);
if (false
== convert_string_to_int(timestamp_view.substr(0, dot_position), timestamp))
{
if (false == convert_string_to_int(line.substr(0, dot_position), timestamp)) {
return false;
}

epochtime_t timestamp_nanoseconds;
if (false
== convert_string_to_int(
timestamp_view.substr(nanosecond_start, cNanosecondDigits),
line.substr(nanosecond_start, cNanosecondDigits),
timestamp_nanoseconds
))
{
Expand Down Expand Up @@ -1072,14 +1070,14 @@ void TimestampPattern::insert_formatted_timestamp(epochtime_t timestamp, string&
case 'E': // UNIX epoch milliseconds
// Note: this timestamp format is required to make up the entire timestamp, so
// this is safe
new_msg = std::to_string(timestamp);
new_msg = to_string(timestamp);
break;

case 'F': { // Nanosecond precision floating point UNIX epoch timestamp
constexpr auto cNanosecondDigits = 9;
// Note: this timestamp format is required to make up the entire timestamp, so
// this is safe
new_msg = std::to_string(timestamp);
new_msg = to_string(timestamp);
new_msg.insert(new_msg.end() - cNanosecondDigits, '.');
break;
}
Expand Down

0 comments on commit 22e5ad4

Please sign in to comment.