static VALUE handle_sequence(rb_yaml_parser_t *parser) { VALUE handler = handler_for_tag(parser, parser->event.data.sequence_start.tag); VALUE arr = rb_ary_new(); VALUE node; while ((node = get_node(parser)) != Qundef) { rb_ary_push(arr, node); } return interpret_value(parser, arr, handler); }
static VALUE handle_scalar(rb_yaml_parser_t *parser) { char *val = (char*)parser->event.data.scalar.value; char *tag = (char*)parser->event.data.scalar.tag; if (parser->event.data.scalar.style == YAML_PLAIN_SCALAR_STYLE && tag == NULL) { tag = detect_scalar_type(val, parser->event.data.scalar.length); } if (tag == NULL) { tag = "tag:yaml.org,2002:str"; } VALUE handler = handler_for_tag(parser, (yaml_char_t *)tag); VALUE scalarval = rb_str_new(val, parser->event.data.scalar.length); return interpret_value(parser, scalarval, handler); }
static VALUE handle_mapping(rb_yaml_parser_t *parser) { VALUE handler = handler_for_tag(parser, parser->event.data.mapping_start.tag); VALUE hash = rb_hash_new(); VALUE key_node; while ((key_node = get_node(parser)) != Qundef) { VALUE value_node = get_node(parser); if (value_node == Qundef) { value_node = Qnil; } rb_hash_aset(hash, key_node, value_node); } return interpret_value(parser, hash, handler); }
//--------------------------------------------------------------------------- void JsTree::interpret_trace_data_in_data(xmlNodePtr data, std::string& json) { //Format: "text": "name", "data": {"offset": "offset_hexa", "dataValue": "value (value_in_hexa)"} std::string offset; //Decimal to hexa std::string name; std::string value; //decimal + hexa if numerical xmlChar *offset_c = xmlGetNoNsProp(data, (const unsigned char*)"offset"); if (offset_c != NULL) offset = (const char *)offset_c; xmlChar *name_c = xmlGetNoNsProp(data, (const unsigned char*)"name"); if (name_c != NULL) name = std::string((const char *)name_c); xmlChar *value_c = xmlNodeGetContent(data); if (value_c != NULL) value = std::string((const char *)value_c); json += ", \"text\":\""; json += name; //Block data json += "\", \"data\":{"; bool coma = false; if (offset_c) { interpret_offset(offset, coma, json); coma = true; } if (value.length()) { interpret_value(value, coma, json); coma = true; } json += "}"; }