equal
deleted
inserted
replaced
40 SEQUENCE, |
40 SEQUENCE, |
41 MAPPING, |
41 MAPPING, |
42 MAP_KEY |
42 MAP_KEY |
43 }; |
43 }; |
44 |
44 |
|
45 std::string rootName = "yaml"; |
45 xmlpp::Element* current; |
46 xmlpp::Element* current; |
46 std::vector<Mode> mode; |
47 std::vector<Mode> mode; |
47 |
48 |
48 static int readFromInput(void* instance, unsigned char* buffer, size_t size, size_t* length) { |
49 static int readFromInput(void* instance, unsigned char* buffer, size_t size, size_t* length) { |
49 std::istream* input = ((XMLDocumentConstructor*) instance)->input; |
50 std::istream* input = ((XMLDocumentConstructor*) instance)->input; |
50 input->read((char*) buffer, size); |
51 input->read((char*) buffer, size); |
51 *length = input->gcount(); |
52 *length = input->gcount(); |
52 return (input->good() || input->eof()) ? 1 : 0; |
53 return (input->good() || input->eof()) ? 1 : 0; |
53 } |
54 } |
54 |
55 |
55 /** |
56 /** |
56 * Both YAML and XML strings are in UTF-8. |
57 * Both YAML and XML strings are in UTF-8. |
57 */ |
58 */ |
58 const char* y2x(yaml_char_t* value) { |
59 const char* y2x(yaml_char_t* value) { |
59 return value ? (const char*) value : ""; |
60 return value ? (const char*) value : ""; |
75 } |
76 } |
76 |
77 |
77 virtual ~XMLDocumentConstructor() { |
78 virtual ~XMLDocumentConstructor() { |
78 yaml_parser_delete(&yamlParser); |
79 yaml_parser_delete(&yamlParser); |
79 } |
80 } |
80 |
81 |
81 void setOption(const std::string& uri, const std::string& value) { |
82 void setOption(const std::string& uri, const std::string& value) { |
|
83 if (uri == "root-name") rootName = value; |
|
84 else throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“"); |
82 } |
85 } |
83 |
86 |
84 void process() { |
87 void process() { |
85 current = parser->get_document()->create_root_node("yaml"); |
88 current = parser->get_document()->create_root_node(rootName); |
86 mode.push_back(Mode::ROOT); |
89 mode.push_back(Mode::ROOT); |
87 std::string itemName; |
90 std::string itemName; |
88 |
91 |
89 while (true) { |
92 while (true) { |
90 yaml_event_t event; |
93 yaml_event_t event; |