mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-11 15:06:43 +00:00
Clean up text key extraction
This commit is contained in:
parent
31e70f2ecc
commit
0922d0b105
2 changed files with 8 additions and 38 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <components/misc/mathutil.hpp>
|
#include <components/misc/mathutil.hpp>
|
||||||
#include <components/misc/rng.hpp>
|
#include <components/misc/rng.hpp>
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
#include <components/settings/settings.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)
|
void CharacterController::handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map)
|
||||||
{
|
{
|
||||||
const std::string &evt = key->second;
|
const std::string &evt = key->second;
|
||||||
|
@ -969,7 +962,7 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil:
|
||||||
if (soundgen.find(' ') != std::string::npos)
|
if (soundgen.find(' ') != std::string::npos)
|
||||||
{
|
{
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
split(soundgen, ' ', tokens);
|
Misc::StringUtils::split(soundgen, tokens);
|
||||||
soundgen = tokens[0];
|
soundgen = tokens[0];
|
||||||
if (tokens.size() >= 2)
|
if (tokens.size() >= 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -153,37 +153,14 @@ namespace
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < tk->list.size();i++)
|
for(size_t i = 0;i < tk->list.size();i++)
|
||||||
{
|
{
|
||||||
const std::string &str = tk->list[i].text;
|
std::vector<std::string> results;
|
||||||
std::string::size_type pos = 0;
|
Misc::StringUtils::split(tk->list[i].text, results, "\r\n");
|
||||||
while(pos < str.length())
|
for (std::string &result : results)
|
||||||
{
|
{
|
||||||
if(::isspace(str[pos]))
|
Misc::StringUtils::trim(result);
|
||||||
{
|
|
||||||
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::lowerCaseInPlace(result);
|
Misc::StringUtils::lowerCaseInPlace(result);
|
||||||
textkeys.emplace(tk->list[i].time, std::move(result));
|
if (!result.empty())
|
||||||
|
textkeys.emplace(tk->list[i].time, std::move(result));
|
||||||
pos = nextpos;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue