diff --git a/log.cpp b/log.cpp index 46823c6..ba58355 100644 --- a/log.cpp +++ b/log.cpp @@ -15,7 +15,7 @@ LogEntry::LogEntry(time_t time_, std::string message_) : time(time_), message(st } -std::string format_log(const LogEntry& entry) { +std::string to_string(const LogEntry& entry) { struct tm tm; char time_as_str[128] = {0}; strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&entry.time, &tm)); diff --git a/log.h b/log.h index 18e0c0f..a45e464 100644 --- a/log.h +++ b/log.h @@ -12,7 +12,7 @@ struct LogEntry { }; extern std::vector log_entries; -std::string format_log(const LogEntry& entry); +std::string to_string(const LogEntry& entry); void print_log(const LogEntry& entry); void log(LogEntry entry, bool print = true); void log(std::string entry); diff --git a/logcat_entry.cpp b/logcat_entry.cpp index edcde21..12da149 100644 --- a/logcat_entry.cpp +++ b/logcat_entry.cpp @@ -9,7 +9,30 @@ static const Pcre2Regex LogcatEntryRegex("^\\s*(\\d+)(?:\\.\\d+)?(?:\\s+([\\w\\d._-]+))?\\s+(\\d+)\\s+(\\d+)\\s+([A-Z])\\s+(.+?)\\s*:\\s(.*)$"); static const Pcre2Regex BufferRegex("^--------- (?:beginning of|switch to) (\\w+)$"); -Priority priority_from(char c) { +const char* to_string(Priority priority) { + switch (priority) { + case Priority::Verbose: return "Verbose"; + case Priority::Debug: return "Debug"; + case Priority::Info: return "Info"; + case Priority::Warn: return "Warning"; + case Priority::Error: return "Error"; + case Priority::Fatal: return "Fatal"; + case Priority::Unknown: return "Unknown"; + } +} + +const char* to_string(Buffer buffer) { + switch (buffer) { + case Buffer::Main: return "Main"; + case Buffer::System: return "System"; + case Buffer::Radio: return "Radio"; + case Buffer::Events: return "Events"; + case Buffer::Crash: return "Crash"; + case Buffer::Unknown: return "Unknown"; + } +} + +static inline Priority priority_from(char c) { switch (c) { case 'V': return Priority::Verbose; case 'D': return Priority::Debug; @@ -21,29 +44,6 @@ Priority priority_from(char c) { } } -const char* priority_to(Priority priority) { - switch (priority) { - case Priority::Verbose: return "Verbose"; - case Priority::Debug: return "Debug"; - case Priority::Info: return "Info"; - case Priority::Warn: return "Warning"; - case Priority::Error: return "Error"; - case Priority::Fatal: return "Fatal"; - default: return "Unknown"; - } -} - -const char* buffer_to(Buffer buffer) { - switch (buffer) { - case Buffer::Main: return "Main"; - case Buffer::System: return "System"; - case Buffer::Radio: return "Radio"; - case Buffer::Events: return "Events"; - case Buffer::Crash: return "Crash"; - default: return "Unknown"; - } -} - static inline long to_long(const char* str, const char* expected_end) { char* endptr; diff --git a/logcat_entry.h b/logcat_entry.h index bb3c517..0c61ef7 100644 --- a/logcat_entry.h +++ b/logcat_entry.h @@ -34,9 +34,8 @@ struct LogcatEntry { std::string message; }; -Priority priority_from(char c); -const char* priority_to(Priority priority); -const char* buffer_to(Buffer buffer); +const char* to_string(Priority priority); +const char* to_string(Buffer buffer); std::optional try_parse_logcat_entry(char* buf, size_t length, Buffer buffer); std::optional try_parse_buffer(char* buf, size_t length); diff --git a/windows/logs.cpp b/windows/logs.cpp index ba4d2da..2fba225 100644 --- a/windows/logs.cpp +++ b/windows/logs.cpp @@ -59,7 +59,7 @@ void logs_window(ImFont* monospace_font, bool* __restrict autoscrolling, bool* _ if (!text.empty()) { text += '\n'; } - text += format_log(entry); + text += to_string(entry); } ImGui::SetClipboardText(text.c_str()); } diff --git a/windows/main.cpp b/windows/main.cpp index d7518cb..9aebc3a 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -38,8 +38,8 @@ static inline void render_table(ImFont* monospace_font, std::vector } if (ImGui::TableSetColumnIndex(2)) ImGui::Text("%zu", logcat_entry->pid); if (ImGui::TableSetColumnIndex(3)) ImGui::Text("%zu", logcat_entry->tid); - if (ImGui::TableSetColumnIndex(4)) ImGui::TextUnformatted(buffer_to(logcat_entry->buffer)); - if (ImGui::TableSetColumnIndex(5)) ImGui::TextUnformatted(priority_to(logcat_entry->priority)); + if (ImGui::TableSetColumnIndex(4)) ImGui::TextUnformatted(to_string(logcat_entry->buffer)); + if (ImGui::TableSetColumnIndex(5)) ImGui::TextUnformatted(to_string(logcat_entry->priority)); if (ImGui::TableSetColumnIndex(6)) ImGui::TextUnformatted(logcat_entry->tag); if (ImGui::TableSetColumnIndex(7)) ImGui::TextUnformatted(logcat_entry->message); }