mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Clean up text key extraction
This commit is contained in:
parent
31e70f2ecc
commit
0922d0b105
@ -23,6 +23,7 @@
|
||||
|
||||
#include <components/misc/mathutil.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
@ -942,14 +943,6 @@ CharacterController::~CharacterController()
|
||||
}
|
||||
}
|
||||
|
||||
void split(const std::string &s, char delim, std::vector<std::string> &elems) {
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
while (std::getline(ss, item, delim)) {
|
||||
elems.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterController::handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map)
|
||||
{
|
||||
const std::string &evt = key->second;
|
||||
@ -969,7 +962,7 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil:
|
||||
if (soundgen.find(' ') != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
split(soundgen, ' ', tokens);
|
||||
Misc::StringUtils::split(soundgen, tokens);
|
||||
soundgen = tokens[0];
|
||||
if (tokens.size() >= 2)
|
||||
{
|
||||
|
@ -153,37 +153,14 @@ namespace
|
||||
{
|
||||
for(size_t i = 0;i < tk->list.size();i++)
|
||||
{
|
||||
const std::string &str = tk->list[i].text;
|
||||
std::string::size_type pos = 0;
|
||||
while(pos < str.length())
|
||||
std::vector<std::string> results;
|
||||
Misc::StringUtils::split(tk->list[i].text, results, "\r\n");
|
||||
for (std::string &result : results)
|
||||
{
|
||||
if(::isspace(str[pos]))
|
||||
{
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string::size_type nextpos = std::min(str.find('\r', pos), str.find('\n', pos));
|
||||
if(nextpos != std::string::npos)
|
||||
{
|
||||
do {
|
||||
nextpos--;
|
||||
} while(nextpos > pos && ::isspace(str[nextpos]));
|
||||
nextpos++;
|
||||
}
|
||||
else if(::isspace(*str.rbegin()))
|
||||
{
|
||||
std::string::const_iterator last = str.end();
|
||||
do {
|
||||
--last;
|
||||
} while(last != str.begin() && ::isspace(*last));
|
||||
nextpos = std::distance(str.begin(), ++last);
|
||||
}
|
||||
std::string result = str.substr(pos, nextpos-pos);
|
||||
Misc::StringUtils::trim(result);
|
||||
Misc::StringUtils::lowerCaseInPlace(result);
|
||||
textkeys.emplace(tk->list[i].time, std::move(result));
|
||||
|
||||
pos = nextpos;
|
||||
if (!result.empty())
|
||||
textkeys.emplace(tk->list[i].time, std::move(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user