Rename some functions to to_string
This commit is contained in:
parent
5f13a1c1c4
commit
042ed355d5
2
log.cpp
2
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));
|
||||
|
|
2
log.h
2
log.h
|
@ -12,7 +12,7 @@ struct LogEntry {
|
|||
};
|
||||
extern std::vector<LogEntry> 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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<LogcatEntry> try_parse_logcat_entry(char* buf, size_t length, Buffer buffer);
|
||||
std::optional<Buffer> try_parse_buffer(char* buf, size_t length);
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue