mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
TextUnformatted: Using memchr(), fixed not properly testing for text_end bound + comments.
Internals: Added ImStreolRange() + used in LogRenderedText() + comments.
This commit is contained in:
41
imgui.cpp
41
imgui.cpp
@ -1203,10 +1203,8 @@ char* ImStrdup(const char *str)
|
||||
|
||||
const char* ImStrchrRange(const char* str, const char* str_end, char c)
|
||||
{
|
||||
for ( ; str < str_end; str++)
|
||||
if (*str == c)
|
||||
return str;
|
||||
return NULL;
|
||||
const char* p = (const char*)memchr(str, (int)c, str_end - str);
|
||||
return p;
|
||||
}
|
||||
|
||||
int ImStrlenW(const ImWchar* str)
|
||||
@ -1216,6 +1214,13 @@ int ImStrlenW(const ImWchar* str)
|
||||
return n;
|
||||
}
|
||||
|
||||
// Find end-of-line. Return pointer will point to either first \n, either str_end.
|
||||
const char* ImStreolRange(const char* str, const char* str_end)
|
||||
{
|
||||
const char* p = (const char*)memchr(str, '\n', str_end - str);
|
||||
return p ? p : str_end;
|
||||
}
|
||||
|
||||
const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin) // find beginning-of-line
|
||||
{
|
||||
while (buf_mid_line > buf_begin && buf_mid_line[-1] != '\n')
|
||||
@ -8343,29 +8348,17 @@ void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char*
|
||||
for (;;)
|
||||
{
|
||||
// Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
|
||||
const char* line_end = text_remaining;
|
||||
while (line_end < text_end)
|
||||
if (*line_end == '\n')
|
||||
break;
|
||||
else
|
||||
line_end++;
|
||||
if (line_end >= text_end)
|
||||
line_end = NULL;
|
||||
|
||||
const bool is_first_line = (text == text_remaining);
|
||||
bool is_last_line = false;
|
||||
if (line_end == NULL)
|
||||
const char* line_start = text_remaining;
|
||||
const char* line_end = ImStreolRange(line_start, text_end);
|
||||
const bool is_first_line = (line_start == text);
|
||||
const bool is_last_line = (line_end == text_end);
|
||||
if (!is_last_line || (line_start != line_end))
|
||||
{
|
||||
is_last_line = true;
|
||||
line_end = text_end;
|
||||
}
|
||||
if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
|
||||
{
|
||||
const int char_count = (int)(line_end - text_remaining);
|
||||
const int char_count = (int)(line_end - line_start);
|
||||
if (log_new_line || !is_first_line)
|
||||
LogText(IM_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
|
||||
LogText(IM_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, line_start);
|
||||
else
|
||||
LogText(" %.*s", char_count, text_remaining);
|
||||
LogText(" %.*s", char_count, line_start);
|
||||
}
|
||||
|
||||
if (is_last_line)
|
||||
|
Reference in New Issue
Block a user