Fixed ImGuiTextFilter triming of leading/trailing blanks. Documented "Filtering" section of demo better.
diff --git a/imgui.cpp b/imgui.cpp
index 5e9add5..c54ac6c 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -725,6 +725,7 @@
//-----------------------------------------------------------------------------
+// Helper: Key->value storage
void ImGuiStorage::Clear()
{
Data.clear();
@@ -797,6 +798,7 @@
//-----------------------------------------------------------------------------
+// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
ImGuiTextFilter::ImGuiTextFilter()
{
InputBuf[0] = 0;
@@ -888,6 +890,7 @@
//-----------------------------------------------------------------------------
+// Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::append(const char* fmt, ...)
{
va_list args;
@@ -5854,7 +5857,12 @@
if (ImGui::CollapsingHeader("Filtering"))
{
static ImGuiTextFilter filter;
- filter.Draw();
+ ImGui::Text("Filter usage:\n"
+ " \"\" display all lines\n"
+ " \"xxx\" display lines containing \"xxx\"\n"
+ " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
+ " \"-xxx\" hide lines containing \"xxx\"");
+ filter.Draw();
const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
if (filter.PassFilter(lines[i]))
diff --git a/imgui.h b/imgui.h
index d1574b6..0f6ed9d 100644
--- a/imgui.h
+++ b/imgui.h
@@ -107,7 +107,7 @@
// Helpers at bottom of the file:
// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only
-// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
+// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
// - struct ImDrawList // Draw command list
@@ -449,7 +449,7 @@
bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
};
-// Helper: Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
+// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
struct ImGuiTextFilter
{
struct TextRange
@@ -463,7 +463,7 @@
const char* end() const { return e; }
bool empty() const { return b == e; }
char front() const { return *b; }
- static bool isblank(char c) { return c == ' ' && c == '\t'; }
+ static bool isblank(char c) { return c == ' ' || c == '\t'; }
void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
void split(char separator, ImVector<TextRange>& out);
};