1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-24 08:53:07 +00:00

Move function definition to header file

This commit is contained in:
ddbb07 2025-11-26 16:55:05 +01:00
parent 3dec065dff
commit aec63843f7
2 changed files with 27 additions and 25 deletions

View file

@ -1,5 +1,4 @@
#include "settingswindow.hpp"
#include "weightedsearch.hpp"
#include <array>
#include <iomanip>
@ -43,6 +42,7 @@
#include "../mwlua/luamanagerimp.hpp"
#include "confirmationdialog.hpp"
#include "weightedsearch.hpp"
namespace
{
@ -942,28 +942,6 @@ namespace MWGui
mControlsBox->setVisibleVScroll(true);
}
std::vector<std::string> generatePatternArray(const MyGUI::UString& inputString)
{
if (inputString.empty() || inputString.find_first_not_of(" ") == std::string::npos)
return std::vector<std::string>();
std::string inputStringLowerCase = Misc::StringUtils::lowerCase(inputString);
std::istringstream stringStream(inputStringLowerCase);
return { std::istream_iterator<std::string>(stringStream), std::istream_iterator<std::string>() };
}
size_t weightedSearch(const std::string& corpus, const std::vector<std::string>& patternArray)
{
if (patternArray.empty())
return 1;
std::string corpusLowerCase = Misc::StringUtils::lowerCase(corpus);
size_t numberOfMatches = 0;
for (const std::string& word : patternArray)
numberOfMatches += corpusLowerCase.find(word) != std::string::npos ? 1 : 0;
return numberOfMatches;
}
void SettingsWindow::renderScriptSettings()
{
mScriptAdapter->detach();

View file

@ -1,15 +1,39 @@
#ifndef MWGUI_WEIGHTEDSEARCH_H
#define MWGUI_WEIGHTEDSEARCH_H
#include <cstddef>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include <MyGUI_UString.h>
#include <components/misc/strings/lower.hpp>
namespace MWGui
{
std::vector<std::string> generatePatternArray(const MyGUI::UString& inputString);
std::size_t weightedSearch(const std::string& corpus, const std::vector<std::string>& patternArray);
std::vector<std::string> generatePatternArray(const MyGUI::UString& inputString)
{
if (inputString.empty() || inputString.find_first_not_of(" ") == std::string::npos)
return std::vector<std::string>();
std::string inputStringLowerCase = Misc::StringUtils::lowerCase(inputString);
std::istringstream stringStream(inputStringLowerCase);
return { std::istream_iterator<std::string>(stringStream), std::istream_iterator<std::string>() };
}
std::size_t weightedSearch(const std::string& corpus, const std::vector<std::string>& patternArray)
{
if (patternArray.empty())
return 1;
std::string corpusLowerCase = Misc::StringUtils::lowerCase(corpus);
std::size_t numberOfMatches = 0;
for (const std::string& word : patternArray)
numberOfMatches += corpusLowerCase.find(word) != std::string::npos ? 1 : 0;
return numberOfMatches;
}
}
#endif