Use strncmp

This commit is contained in:
blankie 2023-01-23 21:29:37 +07:00
parent defaa53a40
commit 1aa93dfea2
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 5 additions and 10 deletions

View File

@ -102,10 +102,6 @@ std::optional<LogcatEntry> try_parse_logcat_entry(char* buf, size_t length, Buff
return std::move(logcat_entry); return std::move(logcat_entry);
} }
static bool substr_equal(const char* lhs_str, size_t lhs_length, const char* rhs_str) {
return lhs_length == strlen(rhs_str) && memcmp(lhs_str, rhs_str, lhs_length * sizeof(char)) == 0;
}
std::optional<Buffer> try_parse_buffer(char* buf, size_t length) { std::optional<Buffer> try_parse_buffer(char* buf, size_t length) {
regmatch_t matches[2]; regmatch_t matches[2];
matches[0].rm_so = 0; matches[0].rm_so = 0;
@ -119,11 +115,10 @@ std::optional<Buffer> try_parse_buffer(char* buf, size_t length) {
} }
const char* buffer_str = &buf[matches[1].rm_so]; const char* buffer_str = &buf[matches[1].rm_so];
size_t buffer_length = static_cast<size_t>(matches[1].rm_eo - matches[1].rm_so); if (!strncmp(buffer_str, "main", 4)) return Buffer::Main;
if (substr_equal(buffer_str, buffer_length, "main")) return Buffer::Main; if (!strncmp(buffer_str, "system", 6)) return Buffer::System;
if (substr_equal(buffer_str, buffer_length, "system")) return Buffer::System; if (!strncmp(buffer_str, "radio", 5)) return Buffer::Radio;
if (substr_equal(buffer_str, buffer_length, "radio")) return Buffer::Radio; if (!strncmp(buffer_str, "events", 6)) return Buffer::Events;
if (substr_equal(buffer_str, buffer_length, "events")) return Buffer::Events; if (!strncmp(buffer_str, "crash", 5)) return Buffer::Crash;
if (substr_equal(buffer_str, buffer_length, "crash")) return Buffer::Crash;
return Buffer::Unknown; return Buffer::Unknown;
} }