Skip to content

Commit

Permalink
Strip seemingly unecessary tests, as UTF-8 decoder can not return nul…
Browse files Browse the repository at this point in the history
…l since 9cca1b2
  • Loading branch information
ocornut committed Jan 12, 2023
1 parent 55b8ce9 commit ccf94e2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
7 changes: 1 addition & 6 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
{
unsigned int c = 0;
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
if (c != 0)
AddInputCharacter(c);
AddInputCharacter(c);
}
}

Expand Down Expand Up @@ -2032,8 +2031,6 @@ int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const cha
{
unsigned int c;
in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
if (c == 0)
break;
*buf_out++ = (ImWchar)c;
}
*buf_out = 0;
Expand All @@ -2049,8 +2046,6 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
{
unsigned int c;
in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
if (c == 0)
break;
char_count++;
}
return char_count;
Expand Down
15 changes: 1 addition & 14 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3382,6 +3382,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
bool inside_word = true;

const char* s = text;
IM_ASSERT(text_end != NULL);
while (s < text_end)
{
unsigned int c = (unsigned int)*s;
Expand All @@ -3390,8 +3391,6 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
next_s = s + 1;
else
next_s = s + ImTextCharFromUtf8(&c, s, text_end);
if (c == 0)
break;

if (c < 32)
{
Expand Down Expand Up @@ -3497,15 +3496,9 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
const char* prev_s = s;
unsigned int c = (unsigned int)*s;
if (c < 0x80)
{
s += 1;
}
else
{
s += ImTextCharFromUtf8(&c, s, text_end);
if (c == 0) // Malformed UTF-8?
break;
}

if (c < 32)
{
Expand Down Expand Up @@ -3647,15 +3640,9 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im
// Decode and advance source
unsigned int c = (unsigned int)*s;
if (c < 0x80)
{
s += 1;
}
else
{
s += ImTextCharFromUtf8(&c, s, text_end);
if (c == 0) // Malformed UTF-8?
break;
}

if (c < 32)
{
Expand Down
4 changes: 1 addition & 3 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4407,12 +4407,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
const int clipboard_len = (int)strlen(clipboard);
ImWchar* clipboard_filtered = (ImWchar*)IM_ALLOC((clipboard_len + 1) * sizeof(ImWchar));
int clipboard_filtered_len = 0;
for (const char* s = clipboard; *s; )
for (const char* s = clipboard; *s != 0; )
{
unsigned int c;
s += ImTextCharFromUtf8(&c, s, NULL);
if (c == 0)
break;
if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Clipboard))
continue;
clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
Expand Down

0 comments on commit ccf94e2

Please sign in to comment.