diff options
| author | San Jacobs | 2025-12-11 20:44:02 +0100 |
|---|---|---|
| committer | San Jacobs | 2025-12-11 20:44:02 +0100 |
| commit | cb7ef81fd339199c69eccd93105c13d2a1f41f71 (patch) | |
| tree | 7109109bd690e91ff74ef2c09605e5626c1d9179 /src/wav/xml/helpers.odin | |
| parent | 00121d7c14a3bfa03c5eeb6c28b5edf060baf029 (diff) | |
| download | better-report-cb7ef81fd339199c69eccd93105c13d2a1f41f71.tar.gz better-report-cb7ef81fd339199c69eccd93105c13d2a1f41f71.tar.bz2 better-report-cb7ef81fd339199c69eccd93105c13d2a1f41f71.zip | |
We can now generate reports straight from the WAVs! No CSV needed!
Diffstat (limited to 'src/wav/xml/helpers.odin')
| -rw-r--r-- | src/wav/xml/helpers.odin | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/wav/xml/helpers.odin b/src/wav/xml/helpers.odin new file mode 100644 index 0000000..79f2d72 --- /dev/null +++ b/src/wav/xml/helpers.odin @@ -0,0 +1,52 @@ +package encoding_xml + +/* + An XML 1.0 / 1.1 parser + + Copyright 2021-2022 Jeroen van Rijn <nom@duclavier.com>. + Made available under Odin's license. + + This file contains helper functions. +*/ + + +// Find parent's nth child with a given ident. +find_child_by_ident :: proc(doc: ^Document, parent_id: Element_ID, ident: string, nth := 0) -> (res: Element_ID, found: bool) { + tag := doc.elements[parent_id] + + count := 0 + for v in tag.value { + switch child_id in v { + case string: continue + case Element_ID: + child := doc.elements[child_id] + /* + Skip commments. They have no name. + */ + if child.kind != .Element { continue } + + /* + If the ident matches and it's the nth such child, return it. + */ + if child.ident == ident { + if count == nth { return child_id, true } + count += 1 + } + } + + } + return 0, false +} + +// Find an attribute by key. +find_attribute_val_by_key :: proc(doc: ^Document, parent_id: Element_ID, key: string) -> (val: string, found: bool) { + tag := doc.elements[parent_id] + + for attr in tag.attribs { + /* + If the ident matches, we're done. There can only ever be one attribute with the same name. + */ + if attr.key == key { return attr.val, true } + } + return "", false +} |