diff --git a/src/dawnshared/util/string.hpp b/src/dawnshared/util/string.hpp index c9260ea2..32b76023 100644 --- a/src/dawnshared/util/string.hpp +++ b/src/dawnshared/util/string.hpp @@ -147,4 +147,22 @@ static inline std::string stringReplaceAll( startPos += replace.length(); } return newString; +} + +/** + * Joins a vector of strings into a single string, using a delimiter. + * + * @param strings Vector of strings to join. + * @param delim Delimiter to join the strings with. + */ +static inline std::string stringJoin( + const std::vector &strings, + const std::string &delim +) { + std::string result; + for(size_t i = 0; i < strings.size(); i++) { + if(i > 0) result += delim; + result += strings[i]; + } + return result; } \ No newline at end of file diff --git a/src/dawntools/vnscenetool/events/VNTextEventParser.cpp b/src/dawntools/vnscenetool/events/VNTextEventParser.cpp index 67e90e59..d92ef3ec 100644 --- a/src/dawntools/vnscenetool/events/VNTextEventParser.cpp +++ b/src/dawntools/vnscenetool/events/VNTextEventParser.cpp @@ -22,8 +22,19 @@ int32_t VNTextParser::onParse( struct VNText *out, std::string *error ) { + std::string innerXml = node->innerXml; + + // Split by newlines, then trim each line. + std::vector lines = stringSplit(innerXml, "\n"); + std::vector finalLines; + for(auto it = lines.begin(); it != lines.end(); ++it) { + auto newLine = stringTrim(*it); + if(newLine.length() > 0) finalLines.push_back(newLine); + } + std::string finalXml = stringJoin(finalLines, "\n"); + out->language = values["lang"]; - out->text = stringParser(node->innerXml, error); + out->text = stringParser(finalXml, error); return error->length() == 0 ? 0 : -1; }