mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
InputText: restore truncating, now between UTF-8 codepoint. (#9029)
Amende612536,2a194e2.
This commit is contained in:
parent
8df962a6ed
commit
3c578fa87e
4 changed files with 24 additions and 8 deletions
22
imgui.cpp
22
imgui.cpp
|
|
@ -2663,17 +2663,29 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e
|
|||
return bytes_count;
|
||||
}
|
||||
|
||||
const char* ImTextFindPreviousUtf8Codepoint(const char* in_text_start, const char* in_text_curr)
|
||||
const char* ImTextFindPreviousUtf8Codepoint(const char* in_text_start, const char* in_p)
|
||||
{
|
||||
while (in_text_curr > in_text_start)
|
||||
while (in_p > in_text_start)
|
||||
{
|
||||
in_text_curr--;
|
||||
if ((*in_text_curr & 0xC0) != 0x80)
|
||||
return in_text_curr;
|
||||
in_p--;
|
||||
if ((*in_p & 0xC0) != 0x80)
|
||||
return in_p;
|
||||
}
|
||||
return in_text_start;
|
||||
}
|
||||
|
||||
const char* ImTextFindValidUtf8CodepointEnd(const char* in_text_start, const char* in_text_end, const char* in_p)
|
||||
{
|
||||
if (in_text_start == in_p)
|
||||
return in_text_start;
|
||||
const char* prev = ImTextFindPreviousUtf8Codepoint(in_text_start, in_p);
|
||||
unsigned int prev_c;
|
||||
int prev_c_len = ImTextCharFromUtf8(&prev_c, prev, in_text_end);
|
||||
if (prev_c != IM_UNICODE_CODEPOINT_INVALID && prev_c_len <= (int)(in_p - prev))
|
||||
return in_p;
|
||||
return prev;
|
||||
}
|
||||
|
||||
int ImTextCountLines(const char* in_text, const char* in_text_end)
|
||||
{
|
||||
if (in_text_end == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue