mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-07 10:05:13 -05:00
cargo: version 0.28.1
- Switch back to IndexMap for attributes as order matters - Add a method to sort the attributes by their key
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "kbinxml"
|
||||
version = "0.27.0"
|
||||
version = "0.28.1"
|
||||
authors = ["Matt Bilker <me@mbilker.us>"]
|
||||
description = "An encoder/decoder for Konami's binary XML format used in many of their games."
|
||||
edition = "2018"
|
||||
|
||||
@@ -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<String, String> {
|
||||
fn convert_attributes(attrs: &[(&str, &str)]) -> IndexMap<String, String> {
|
||||
attrs.iter()
|
||||
.map(|(key, value)| (String::from(*key), String::from(*value)))
|
||||
.collect()
|
||||
@@ -44,7 +45,7 @@ pub struct OptionIterator<T: IntoIterator> {
|
||||
#[derive(Clone, Default, PartialEq)]
|
||||
pub struct Node {
|
||||
key: String,
|
||||
attributes: Option<BTreeMap<String, String>>,
|
||||
attributes: Option<IndexMap<String, String>>,
|
||||
children: Option<Vec<Node>>,
|
||||
value: Option<Value>,
|
||||
}
|
||||
@@ -143,12 +144,12 @@ impl Node {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn attributes(&self) -> Option<&BTreeMap<String, String>> {
|
||||
pub fn attributes(&self) -> Option<&IndexMap<String, String>> {
|
||||
self.attributes.as_ref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn attributes_mut(&mut self) -> Option<&mut BTreeMap<String, String>> {
|
||||
pub fn attributes_mut(&mut self) -> Option<&mut IndexMap<String, String>> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user