diff --git a/Cargo.toml b/Cargo.toml index 4603b97..a7ac339 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kbinxml" -version = "0.27.0" +version = "0.28.1" authors = ["Matt Bilker "] description = "An encoder/decoder for Konami's binary XML format used in many of their games." edition = "2018" diff --git a/src/node/mod.rs b/src/node/mod.rs index 50aa6b5..10502be 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -1,8 +1,9 @@ -use std::collections::BTreeMap; use std::fmt; use std::iter::IntoIterator; use std::mem; +use indexmap::IndexMap; + use crate::value::Value; mod collection; @@ -24,7 +25,7 @@ cfg_if! { } // The attributes argument is very hard to generalize -fn convert_attributes(attrs: &[(&str, &str)]) -> BTreeMap { +fn convert_attributes(attrs: &[(&str, &str)]) -> IndexMap { attrs.iter() .map(|(key, value)| (String::from(*key), String::from(*value))) .collect() @@ -44,7 +45,7 @@ pub struct OptionIterator { #[derive(Clone, Default, PartialEq)] pub struct Node { key: String, - attributes: Option>, + attributes: Option>, children: Option>, value: Option, } @@ -143,12 +144,12 @@ impl Node { } #[inline] - pub fn attributes(&self) -> Option<&BTreeMap> { + pub fn attributes(&self) -> Option<&IndexMap> { self.attributes.as_ref() } #[inline] - pub fn attributes_mut(&mut self) -> Option<&mut BTreeMap> { + pub fn attributes_mut(&mut self) -> Option<&mut IndexMap> { self.attributes.as_mut() } @@ -210,6 +211,12 @@ impl Node { attributes.insert(key.into(), value.into()) } + pub fn sort_attrs(&mut self) { + if let Some(ref mut attributes) = self.attributes { + attributes.sort_keys(); + } + } + pub fn append_child(&mut self, value: Node) { let children = self.children.get_or_insert_with(Default::default); children.push(value);