diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index aee94f15b7..62c130b36e 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -23,6 +23,7 @@ #include #include +#include #include @@ -942,14 +943,6 @@ CharacterController::~CharacterController() } } -void split(const std::string &s, char delim, std::vector &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 tokens; - split(soundgen, ' ', tokens); + Misc::StringUtils::split(soundgen, tokens); soundgen = tokens[0]; if (tokens.size() >= 2) { diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 81c3d24dcc..0432aef5b4 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -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 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)); } } }