Moved C++ tools out
This commit is contained in:
82
archive/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal file
82
archive/dawntools/vnscenetool/events/VNTextEventParser.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// 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<std::string> VNTextParser::getRequiredAttributes() {
|
||||
return { "lang" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNTextParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNTextParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNText *out,
|
||||
std::string *error
|
||||
) {
|
||||
std::string innerXml = node->innerXml;
|
||||
|
||||
// Split by newlines, then trim each line.
|
||||
std::vector<std::string> lines = stringSplit(innerXml, "\n");
|
||||
std::vector<std::string> 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<std::string> VNTextEventParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNTextEventParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNTextEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> 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;
|
||||
}
|
Reference in New Issue
Block a user