Browse Source

Merge pull request #1757 from Kelimion/xml

[xml] Add `parse_from_string` overload.
Jeroen van Rijn 3 years ago
parent
commit
41a18f078d
2 changed files with 11 additions and 4 deletions
  1. 10 3
      core/encoding/xml/xml_reader.odin
  2. 1 1
      tests/core/encoding/xml/test_core_xml.odin

+ 10 - 3
core/encoding/xml/xml_reader.odin

@@ -493,7 +493,16 @@ parse_from_slice :: proc(data: []u8, options := DEFAULT_Options, path := "", err
 	return doc, .None
 }
 
-parse_from_file :: proc(filename: string, options := DEFAULT_Options, error_handler := default_error_handler, allocator := context.allocator) -> (doc: ^Document, err: Error) {
+parse_from_string :: proc(data: string, options := DEFAULT_Options, path := "", error_handler := default_error_handler, allocator := context.allocator) -> (doc: ^Document, err: Error) {
+	_data := transmute([]u8)data
+
+	return parse_from_slice(_data, options, path, error_handler, allocator)
+}
+
+parse :: proc { parse_from_string, parse_from_slice }
+
+// Load an XML file
+load_from_file :: proc(filename: string, options := DEFAULT_Options, error_handler := default_error_handler, allocator := context.allocator) -> (doc: ^Document, err: Error) {
 	context.allocator = allocator
 	options := options
 
@@ -505,8 +514,6 @@ parse_from_file :: proc(filename: string, options := DEFAULT_Options, error_hand
 	return parse_from_slice(data, options, filename, error_handler, allocator)
 }
 
-parse :: proc { parse_from_file, parse_from_slice }
-
 destroy :: proc(doc: ^Document) {
 	if doc == nil { return }
 

+ 1 - 1
tests/core/encoding/xml/test_core_xml.odin

@@ -295,7 +295,7 @@ run_tests :: proc(t: ^testing.T) {
 		path := test_file_path(test.filename)
 		log(t, fmt.tprintf("Trying to parse %v", path))
 
-		doc, err := xml.parse(path, test.options, Silent)
+		doc, err := xml.load_from_file(path, test.options, Silent)
 		defer xml.destroy(doc)
 
 		tree_string := doc_to_string(doc)