From 0b054c48028eb2cd47ee8a1e2d06fdbbffefe28a Mon Sep 17 00:00:00 2001 From: Will Hedgecock Date: Tue, 5 Nov 2024 14:06:07 -0600 Subject: [PATCH] Parse data from either UTF-8 or UTF-16 --- musicxml/src/parser/mod.rs | 4 ++-- musicxml/src/parser/zip_parser.rs | 3 ++- musicxml/tests/MozaChloSample.musicxml | Bin 0 -> 223068 bytes musicxml_internal/src/lib.rs | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100755 musicxml/tests/MozaChloSample.musicxml diff --git a/musicxml/src/parser/mod.rs b/musicxml/src/parser/mod.rs index df6e75a..b494739 100644 --- a/musicxml/src/parser/mod.rs +++ b/musicxml/src/parser/mod.rs @@ -1,6 +1,6 @@ use crate::elements::{ScorePartwise, ScoreTimewise}; use alloc::{collections::BTreeMap, string::String, vec::Vec}; -use musicxml_internal::{ElementDeserializer, ElementSerializer, XmlElement}; +use musicxml_internal::{bytes_to_string, ElementDeserializer, ElementSerializer, XmlElement}; #[cfg(feature = "std")] extern crate std; @@ -45,7 +45,7 @@ fn get_musicxml_contents(data: Vec) -> Result { Err(String::from("Cannot find MusicXML file in compressed archive"))?; } } else { - contents = String::from_utf8(data).or_else(|_| Err(String::from("Invalid UTF-8 data in MusicXML content")))?; + contents = bytes_to_string(&data)?; } Ok(contents) } diff --git a/musicxml/src/parser/zip_parser.rs b/musicxml/src/parser/zip_parser.rs index d8dee86..d44f909 100644 --- a/musicxml/src/parser/zip_parser.rs +++ b/musicxml/src/parser/zip_parser.rs @@ -4,6 +4,7 @@ use alloc::{collections::BTreeMap, vec::Vec}; use crc32fast; use miniz_oxide::deflate::compress_to_vec; use miniz_oxide::inflate::decompress_to_vec; +use musicxml_internal::bytes_to_string; #[cfg(feature = "std")] use std::time::{SystemTime, UNIX_EPOCH}; @@ -247,7 +248,7 @@ impl<'a> ZipArchive<'a> { let decoded_data = decompress_to_vec(&self.zip_data.content[file.relative_offset..(file.relative_offset + file.compressed_size)]) .map_err(|e| e.to_string())?; - String::from_utf8(decoded_data).map_err(|e| e.to_string()) + bytes_to_string(&decoded_data).map_err(|e| e.to_string()) } pub fn iter(&self) -> impl Iterator { diff --git a/musicxml/tests/MozaChloSample.musicxml b/musicxml/tests/MozaChloSample.musicxml new file mode 100755 index 0000000000000000000000000000000000000000..1c7f18aeb24fd84f95ebb0c49714fa216c2f5405 GIT binary patch literal 223068 zcmeHwTXP*ba%MgIAM6`PPwR*|-Az&yB`=#B?VcHXykmR9VS9ETDU!NOOQMFPT2}uf z|3}B}=2v-AKmiG$PzQB82f@&VbwS~h$m^Gh|NH-%i{^he|Ixf}-Ze+f&&_Rf-#j#L zo4e*i^L_KAIc~mbzN3GS=+1}cny%l_-4D&{_U^wm|JwYn+0awZ+Gie`$L5Oe-q7Fg z+BR<6=RVN?pU`(Mo4=y({i^v*^UuwX^zQ#@{@DDM+J0zTzNc?&nveAEJ+*cK`Rya>{{{5~qy4FE4_CTZH#F~`sHZP!ChqB(|3&>iYR;My8uSnB_7^rZs<-s#9kq4Y{6H-q(cHgj*Ay%A-`iPyO?QuI?f=?o-+q@{x4#b> z;GVyw83I+|`B(JknpOt?2kpsI{Ny!_=(fF!891V+zR-L#ZGi^f({FbzwcOJ>UN(QC z-`-K1ujw7o>Jg3MJ^dfw16_bV?wVid3MdV|>wcmC*WXc3?%TeDS|8i5{{yxCru{PJ z?eFND=rwxr4|Em%eMxVmzKT{~xAgcxBl?lv`ndfTUp;F6lUh8X-T58;jS*cDZQNRv z|7*JXdm8^WQ3Af!ZP8wLcW>L{=M{LM@4uq)eQxIrRPj6N-v{~)Gy=|X(wuL1*sFHD z+@tIE%l_Nu>)gKEgAJ_}r~zNX7*B}KHuUea_HU->*gJ0f547$dTPnedg96a{V>>4= z=^nlWe)oa?{Y>9@pt;6+-V)s~_ro~f(;v_)p8VLpi{EhHrpPb!)I)pq=XQQR(eHRe zu768o+O>b+lGuOq^zF7?b$d2I*VjZ5vZFy4p?T>ye*YWbY**X$(B^w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A z@6f1h-5%9L)`W&+x{Xa~FCwV2eBa-aqqO2p9d|}c;`Hh%TJuW?M7Q7@Uz&`F(^+X5 zF{~b@Y|4eR9J@z*le{*;lIX)O_!zx5QB4P_}Kvw5fuGH$gEJs!wZUs}3MOMhdci&^ z8u`(rL-=(Ke&M9)8X>GYUgT&Dwgq6>Z4O| z0+DRv`omGxhCQenN6Mem;TBfzoW3F6`i}B2Ai>jowajeBJVNt(oXSbI)d)+w0+Y^8<7LHyxA9@31^kKK9e&w z3Y+$sa8+GCI~JydsUcN^r(e}5ZmV2fh&YBARV2ez zA@qBq$Hpg)f=9wTw=&>uh^YZ(U^I6?Q~gIF`Q7IR{T55rbIH0htocCWqg^->aO7&aqNA8%ng5v(`q{Dl=%B$Q@PCo>LEj zkEB$r_Qxs>NUMC)GolcS)Xpmn)@MJ&cO=er!QRu)`dg>{0Q_dDeLJmhvub~SuKc|F zeLBnIm?}+|qS|VE?1%O@9rc~G=-Cj`D9`q&JX7+S`s3O5$;Y}jnkeNDIjPy{23qc<~T31Qzs?{)dPkSF(E7`f>E< zw3!iPo$obd&)`rSZ%)c9&8LRZ=AlVEo#sl==9HW-jPhYF!kH}+GrVYiMYWDMlT}tW g6`ZBUGJ5quJmHRVZEmS2AGf(T!1p}R73%5#2N>J900000 literal 0 HcmV?d00001 diff --git a/musicxml_internal/src/lib.rs b/musicxml_internal/src/lib.rs index 6a114b2..2c52e78 100644 --- a/musicxml_internal/src/lib.rs +++ b/musicxml_internal/src/lib.rs @@ -2,9 +2,25 @@ extern crate alloc; +use alloc::borrow::ToOwned; use alloc::string::{String, ToString}; use alloc::vec::Vec; +pub fn bytes_to_string(bytes: &[u8]) -> Result { + String::from_utf8(bytes.to_owned()).or_else(|_| { + let convert = if bytes[0] == 0xFF && bytes[1] == 0xFE { + u16::from_le_bytes + } else { + u16::from_be_bytes + }; + let u16_bytes: Vec = bytes + .chunks_exact(2) + .map(|bytes| convert([bytes[0], bytes[1]])) + .collect(); + String::from_utf16(&u16_bytes).map_err(|_| String::from("Invalid UTF-8 or UTF-16 data in MusicXML content")) + }) +} + #[derive(Debug, Default, PartialEq, Eq)] pub struct XmlElement { pub name: String,