aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/entity/example/entity_example.odin
diff options
context:
space:
mode:
authorjason <jkercher@rlcsystems.com>2022-05-16 13:49:57 -0400
committerjason <jkercher@rlcsystems.com>2022-05-16 13:49:57 -0400
commitfff23e2bbbd1574debce9e0dee894f3cc84a04c4 (patch)
tree4055ea217375d34693861b39fc284e411f7c0366 /core/encoding/entity/example/entity_example.odin
parent97d1a6787189d7630650612f44c393f7a635019a (diff)
parent33895b6d927c70167f3bfa64c6cc1c15c4e428c5 (diff)
merge from upstream and convert to ^File types
Diffstat (limited to 'core/encoding/entity/example/entity_example.odin')
-rw-r--r--core/encoding/entity/example/entity_example.odin76
1 files changed, 76 insertions, 0 deletions
diff --git a/core/encoding/entity/example/entity_example.odin b/core/encoding/entity/example/entity_example.odin
new file mode 100644
index 000000000..6fc377f9d
--- /dev/null
+++ b/core/encoding/entity/example/entity_example.odin
@@ -0,0 +1,76 @@
+package unicode_entity_example
+
+import "core:encoding/xml"
+import "core:strings"
+import "core:mem"
+import "core:fmt"
+import "core:time"
+
+doc_print :: proc(doc: ^xml.Document) {
+ buf: strings.Builder
+ defer strings.destroy_builder(&buf)
+ w := strings.to_writer(&buf)
+
+ xml.print(w, doc)
+ fmt.println(strings.to_string(buf))
+}
+
+_entities :: proc() {
+ doc: ^xml.Document
+ err: xml.Error
+
+ DOC :: #load("../../../../tests/core/assets/XML/unicode.xml")
+
+ OPTIONS :: xml.Options{
+ flags = {
+ .Ignore_Unsupported, .Intern_Comments,
+ },
+ expected_doctype = "",
+ }
+
+ parse_duration: time.Duration
+
+ {
+ time.SCOPED_TICK_DURATION(&parse_duration)
+ doc, err = xml.parse(DOC, OPTIONS)
+ }
+ defer xml.destroy(doc)
+
+ doc_print(doc)
+
+ ms := time.duration_milliseconds(parse_duration)
+
+ speed := (f64(1000.0) / ms) * f64(len(DOC)) / 1_024.0 / 1_024.0
+
+ fmt.printf("Parse time: %.2f ms (%.2f MiB/s).\n", ms, speed)
+ fmt.printf("Error: %v\n", err)
+}
+
+_main :: proc() {
+ using fmt
+
+ options := xml.Options{ flags = { .Ignore_Unsupported, .Intern_Comments, .Unbox_CDATA, .Decode_SGML_Entities }}
+
+ doc, _ := xml.parse(#load("test.html"), options)
+
+ defer xml.destroy(doc)
+ doc_print(doc)
+}
+
+main :: proc() {
+ using fmt
+
+ track: mem.Tracking_Allocator
+ mem.tracking_allocator_init(&track, context.allocator)
+ context.allocator = mem.tracking_allocator(&track)
+
+ // _main()
+ _entities()
+
+ if len(track.allocation_map) > 0 {
+ println()
+ for _, v in track.allocation_map {
+ printf("%v Leaked %v bytes.\n", v.location, v.size)
+ }
+ }
+} \ No newline at end of file