1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include "NodeJSOuptutParser.h"
NodeJSOuptutParser::NodeJSOuptutParser() {}
NodeJSOuptutParser::~NodeJSOuptutParser() {}
NodeJSHandle NodeJSOuptutParser::ParseRef(const JSONElement& ref, std::map<int, NodeJSHandle>& handles)
{
int handleId = ref.namedObject("handle").toInt();
NodeJSHandle h;
h.handleID = handleId;
h.type = ref.namedObject("type").toString();
if(h.type == "undefined") {
h.value = "undefined";
} else if(h.type == "number" || h.type == "boolean") {
h.value = ref.namedObject("text").toString();
} else if(h.type == "string") {
// Make this string repesentable in a single line
h.value << "\"" << ref.namedObject("text").toString() << "\"";
h.value.Replace("\n", "\\n");
h.value.Replace("\t", "\\t");
h.value.Replace("\r", "\\r");
} else if(h.type == "script" || h.type == "function") {
h.value = ref.namedObject("name").toString();
} else if(h.type == "null") {
h.value = "null";
} else if(h.type == "object") {
if(ref.hasNamedObject("protoObject")) {
h.properties.push_back(
std::make_pair(ref.namedObject("protoObject").namedObject("ref").toInt(), "prototype"));
}
if(ref.hasNamedObject("className") && ref.namedObject("className").toString() == "Array") {
h.type = "Array";
h.value = "[]";
} else if(ref.hasNamedObject("text")) {
h.value = ref.namedObject("text").toString();
} else {
h.value = "{...}";
}
JSONElement props = ref.namedObject("properties");
int propsCount = props.arraySize();
for(int n = 0; n < propsCount; ++n) {
JSONElement prop = props.arrayItem(n);
wxString propName;
if(prop.namedObject("name").isString()) {
propName = prop.namedObject("name").toString();
} else if(prop.namedObject("name").isNumber()) {
propName << "[" << prop.namedObject("name").toInt() << "]";
}
int propId = prop.namedObject("ref").toInt();
h.properties.push_back(std::make_pair(propId, propName));
}
}
handles.insert(std::make_pair(handleId, h));
return h;
}
|