NK92 - Search crawling

Do a Log for now.
This commit is contained in:
emerycp
2023-08-01 11:57:26 -04:00
parent 6f2e13e72f
commit 6e38bf2c24
4 changed files with 25 additions and 0 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -34,6 +34,7 @@ namespace Nuake
static Ref<Directory> GetFileTree();
static Ref<File> 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> directory);
static void GetDirectories();

View File

@@ -1,5 +1,6 @@
#include "String.h"
#include <iostream>
#include <regex>
#include <sstream>
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<std::string> String::Split(const std::string& string, char delimiter)
{
std::vector<std::string> result;

View File

@@ -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<std::string> Split(const std::string& string, char delimiter);
static float ToFloat(const std::string& string);