From 6e38bf2c249ebcd6b6d96bb81c64a3ede2c0c8ab Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 11:57:26 -0400 Subject: [PATCH] NK92 - Search crawling Do a Log for now. --- Nuake/src/Core/FileSystem.cpp | 10 ++++++++++ Nuake/src/Core/FileSystem.h | 1 + Nuake/src/Core/String.cpp | 13 +++++++++++++ Nuake/src/Core/String.h | 1 + 4 files changed, 25 insertions(+) diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index c2ed7bac..9dcab855 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -228,5 +228,15 @@ namespace Nuake const auto& split = String::Split(path, '\\'); return String::Split(split[split.size() - 1], '.')[0]; } + + void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) { + const std::string& sanitizedKeyword = String::Sanitize(keyword); + for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) { + if (entry.is_regular_file() && entry.path().filename().string().find(sanitizedKeyword) != std::string::npos) { + std::cout << entry.path() << std::endl; + } + } + } + } diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index f337058f..5a7ea8f4 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -34,6 +34,7 @@ namespace Nuake static Ref GetFileTree(); static Ref GetFile(const std::string& path); static std::string GetFileNameFromPath(const std::string& path); + static void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory); static void ScanDirectory(Ref directory); static void GetDirectories(); diff --git a/Nuake/src/Core/String.cpp b/Nuake/src/Core/String.cpp index 7c4ccc5a..cd68caf7 100644 --- a/Nuake/src/Core/String.cpp +++ b/Nuake/src/Core/String.cpp @@ -1,5 +1,6 @@ #include "String.h" #include +#include #include namespace Nuake @@ -36,6 +37,18 @@ namespace Nuake return result; } + std::string String::Sanitize(const std::string& keyword) { + std::string sanitizedKeyword = keyword; + + // Remove spaces, underscores, and hyphens using regex + sanitizedKeyword = std::regex_replace(sanitizedKeyword, std::regex("[ _-]+"), ""); + + // Convert to lowercase + std::transform(sanitizedKeyword.begin(), sanitizedKeyword.end(), sanitizedKeyword.begin(), ::tolower); + + return sanitizedKeyword; + } + std::vector String::Split(const std::string& string, char delimiter) { std::vector result; diff --git a/Nuake/src/Core/String.h b/Nuake/src/Core/String.h index be3f6aa7..c3b55e17 100644 --- a/Nuake/src/Core/String.h +++ b/Nuake/src/Core/String.h @@ -15,6 +15,7 @@ namespace Nuake static bool EndsWith(const std::string& string, const std::string& end); static bool IsDigit(const char& character); static std::string RemoveWhiteSpace(const std::string& string); + static std::string Sanitize(const std::string& keyword); static std::vector Split(const std::string& string, char delimiter); static float ToFloat(const std::string& string);