// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "VNTextEventParser.hpp" #include "util/parser/TypeParsers.hpp" using namespace Dawn; std::vector VNTextParser::getRequiredAttributes() { return { "lang" }; } std::map VNTextParser::getOptionalAttributes() { return { }; } int32_t VNTextParser::onParse( Xml *node, std::map values, 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(finalXml, error); return error->length() == 0 ? 0 : -1; } // // // // // // // // // // // // // // // // // // // // // // // // // // // std::vector VNTextEventParser::getRequiredAttributes() { return { }; } std::map VNTextEventParser::getOptionalAttributes() { return { }; } int32_t VNTextEventParser::onParse( Xml *node, std::map values, struct VNTextEvent *out, std::string *error ) { int32_t ret; auto itChildren = node->childNodes.begin(); while(itChildren != node->childNodes.end()) { if(itChildren->nodeType != XML_NODE_TYPE_ELEMENT) { ++itChildren; continue; } Xml *child = itChildren->child; // Parse strings if(child->node == "string") { VNText text; ret = (VNTextParser()).parse(child, &text, error); if(ret != 0) return ret; out->texts.push_back(text); } else { *error = "Unknown child node for text event '" + child->node + "'"; return -1; } itChildren++; } return 0; }