Revert using wchar_t functions (9cf94d5 + 2eaf5b0). Big mistake, wchar_t is not guaranteed to be 16-bits.
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 0c3de1a..5e6a510 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -59,7 +59,7 @@
introduced in 1.50 and broken in 1.60. (#1698, #894, #713).
- TextUnformatted(): Fixed a case where large-text path would read bytes past the text_end marker depending
on the position of new lines in the buffer (it wasn't affecting the output but still not the right thing to do!)
-- InputTextMultiline(), RenderText(): Some optimization for very large text buffers, useful for non-optimized builds.
+- RenderText(): Some optimization for very large text buffers, useful for non-optimized builds.
- BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f.
- ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different.
- Drag and Drop: Added GetDragDropPayload() to peek directly into the payload (if any) from anywhere. (#143)
diff --git a/imgui.cpp b/imgui.cpp
index 2fc76f5..34dbca1 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -850,7 +850,6 @@
#include <ctype.h> // toupper, isprint
#include <stdio.h> // vsnprintf, sscanf, printf
-#include <wchar.h> // wcslen
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
#include <stddef.h> // intptr_t
#else
@@ -1220,7 +1219,10 @@
int ImStrlenW(const ImWchar* str)
{
- return (int)wcslen((const wchar_t*)str);
+ //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits
+ int n = 0;
+ while (*str++) n++;
+ return n;
}
// Find end-of-line. Return pointer will point to either first \n, either str_end.
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 4e632a9..c873932 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -36,7 +36,6 @@
#include "imgui_internal.h"
#include <ctype.h> // toupper, isprint
-#include <wchar.h> // wmemchr
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
#include <stddef.h> // intptr_t
#else
@@ -3618,12 +3617,14 @@
// In multi-line mode, we never exit the loop until all lines are counted, so add one extra to the searches_remaining counter.
searches_remaining += is_multiline ? 1 : 0;
int line_count = 0;
- for (const ImWchar* s = text_begin; (s = (const ImWchar*)wcschr((const wchar_t*)s, (wchar_t)'\n')) != NULL; s++)
- {
- line_count++;
- if (searches_result_line_number[0] == -1 && s >= searches_input_ptr[0]) { searches_result_line_number[0] = line_count; if (--searches_remaining <= 0) break; }
- if (searches_result_line_number[1] == -1 && s >= searches_input_ptr[1]) { searches_result_line_number[1] = line_count; if (--searches_remaining <= 0) break; }
- }
+ //for (const ImWchar* s = text_begin; (s = (const ImWchar*)wcschr((const wchar_t*)s, (wchar_t)'\n')) != NULL; s++) // FIXME-OPT: Could use this when wchar_t are 16-bits
+ for (const ImWchar* s = text_begin; *s != 0; s++)
+ if (*s == '\n')
+ {
+ line_count++;
+ if (searches_result_line_number[0] == -1 && s >= searches_input_ptr[0]) { searches_result_line_number[0] = line_count; if (--searches_remaining <= 0) break; }
+ if (searches_result_line_number[1] == -1 && s >= searches_input_ptr[1]) { searches_result_line_number[1] = line_count; if (--searches_remaining <= 0) break; }
+ }
line_count++;
if (searches_result_line_number[0] == -1) searches_result_line_number[0] = line_count;
if (searches_result_line_number[1] == -1) searches_result_line_number[1] = line_count;
@@ -3691,8 +3692,11 @@
break;
if (rect_pos.y < clip_rect.y)
{
- p = (const ImWchar*)wmemchr((const wchar_t*)p, '\n', text_selected_end - p);
- p = p ? p + 1 : text_selected_end;
+ //p = (const ImWchar*)wmemchr((const wchar_t*)p, '\n', text_selected_end - p); // FIXME-OPT: Could use this when wchar_t are 16-bits
+ //p = p ? p + 1 : text_selected_end;
+ while (p < text_selected_end)
+ if (*p++ == '\n')
+ break;
}
else
{