commit 8a16b7a0b8d93b02c17d2d1e555f2225bd57ed3c
Author: david.sorber <david.sorber@jacobs.com>
Date:   Fri Mar 22 13:08:28 2024 -0400

    Tokenize a filter criteria and then search the catalog for feach filter
    criteria token.

diff --git a/src/Catalog.cc b/src/Catalog.cc
index 9628bc9..4c2b3b3 100644
--- a/src/Catalog.cc
+++ b/src/Catalog.cc
@@ -178,16 +178,24 @@ void Catalog::setAllVisible()
 
 void Catalog::filter(const std::string& criteria)
 {
-    // TODO: would be nice if there were a more efficient way to do this
-    for (auto& item : m_catalog)
+    // Tokenize the filter criteria
+    std::vector<std::string_view> tokens;
+    tokenize(criteria, " ", tokens);
+
+    // Iterate over the filter criteria tokens
+    for (auto& token : tokens)
     {
-        if (item.match(criteria))
-        {
-            item.setVisibilty(true);
-        }
-        else
+        // Attempt to match each catalog item
+        for (auto& item : m_catalog)
         {
-            item.setVisibilty(false);
+            if (item.match(token))
+            {
+                item.setVisibilty(true);
+            }
+            else
+            {
+                item.setVisibilty(false);
+            }
         }
     }
 }
diff --git a/src/Catalog.h b/src/Catalog.h
index 9adf832..d979723 100644
--- a/src/Catalog.h
+++ b/src/Catalog.h
@@ -4,11 +4,33 @@
 #include <climits>
 #include <cstdint>
 #include <string>
+#include <string_view>
 #include <vector>
 
 #include "CatalogItem.h"
 
 
+// I mean this should go into some sort of utils
+template<class T>
+static inline void tokenize(
+    T input,
+    std::string delim,
+    std::vector<std::string_view>& tokens)
+{
+    uint32_t prevOffset = 0;
+    auto pos = std::string_view::npos;
+    while ((pos = input.find(delim, prevOffset)) != std::string_view::npos)
+    {
+        tokens.emplace_back(input.data() + prevOffset, (pos - prevOffset));
+        prevOffset = pos + delim.size();
+    }
+
+    // Final (or only one) parameter
+    tokens.emplace_back(input.data() + prevOffset,
+                        (input.size() - prevOffset));
+}
+
+
 class Catalog
 {
 public:
diff --git a/src/CatalogItem.cc b/src/CatalogItem.cc
index 2dd13c0..9a9f29b 100644
--- a/src/CatalogItem.cc
+++ b/src/CatalogItem.cc
@@ -28,6 +28,11 @@ CatalogItem::~CatalogItem()
 }
 
 bool CatalogItem::match(const std::string& criteria)
+{
+    return m_keyLower.find(criteria) != std::string::npos;
+}
+
+bool CatalogItem::match(const std::string_view& criteria)
 {
     return m_keyLower.find(criteria) != std::string::npos;
 }
\ No newline at end of file
diff --git a/src/CatalogItem.h b/src/CatalogItem.h
index cc818b9..669a08f 100644
--- a/src/CatalogItem.h
+++ b/src/CatalogItem.h
@@ -3,6 +3,7 @@
 
 #include <cstdint>
 #include <string>
+#include <string_view>
 
 
 class CatalogItem
@@ -65,7 +66,7 @@ public:
      * @return
      */
     bool match(const std::string& criteria);
-
+    bool match(const std::string_view& criteria);
 
 private:
 
diff --git a/src/main.cc b/src/main.cc
index 1a338c7..9de9a72 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -31,7 +31,7 @@
 #endif
 
 const std::string APP_NAME("pwmgr");
-const std::string VERSION("v0.1.2");
+const std::string VERSION("v0.1.3");
 const std::string DEFAULT_FILEPATH("/home/dsorber/Documents/chicken_soup/chicken_soup.txt.enc");
 
 const std::string BOLD{"\033[1m"};
@@ -50,6 +50,7 @@ const uint32_t BUFFER_SIZE{2048};
 Catalog catalog;
 
 const char* STR_EMPTY = "";
+const char* STR_PWD = "enter password and click \"Load\"";
 const char* STR_LOADING = "Loading...";
 
 static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS =
@@ -178,7 +179,7 @@ int main(int argc, char** argv)
     char filterBuffer[128]{};
     char filePathBuffer[BUFFER_SIZE]{};
     std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(), DEFAULT_FILEPATH.size());
-    const char* statusText = STR_EMPTY;
+    const char* statusText = STR_PWD;
 
     char passwdBuffer[BUFFER_SIZE]{};
     while (! done)
@@ -272,7 +273,7 @@ int main(int argc, char** argv)
                 }
                 ImGui::SameLine();
 
-                ImGui::Text(statusText);
+                ImGui::Text("Status: %s", statusText);
 
                 if (loading)
                 {
@@ -349,7 +350,7 @@ int main(int argc, char** argv)
                                     iter.getValueBuffer(),
                                     iter.getValueBufferSize(),
                                     ImVec2(-FLT_MIN,
-                                           ImGui::GetTextLineHeight() * 4),
+                                               ImGui::GetTextLineHeight() * 5),
                                     MULTILINE_TEXT_FLAGS);
                         }
                     }
