aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-11-24 11:03:45 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-11-24 11:03:45 +0100
commit763c77283c1f9cf22475f4b6cd38073a9e96c832 (patch)
treea8fc24b636290212c006724bbf25f39314982921
parent3243f0863559e40e4c9d7a108b16cdbef554af3c (diff)
downloadcbconv-763c77283c1f9cf22475f4b6cd38073a9e96c832.tar.gz
cbconv-763c77283c1f9cf22475f4b6cd38073a9e96c832.tar.bz2
cbconv-763c77283c1f9cf22475f4b6cd38073a9e96c832.zip
Discard terminating null-bytes at end of strings.
-rw-r--r--src/main.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 0c51ea0..52a8d3f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,13 +31,13 @@ use std::{
/// Parser for length prefixed strings.
///
-/// Cubase uses a string format where the length of the string
-/// is given as a 32 bit big endian word before the actual string
-/// data. The string is also zero terminated, with the zero term
-/// char included in the length.
+/// Cubase uses a string format where the length of the string is given as a 32 bit big endian word
+/// before the actual string data. The string may also be zero terminated, with the zero term char
+/// included in the length. In that case, we trim off the ending zero bytes.
fn cmstring(data: &[u8]) -> IResult<&[u8], &str> {
let (r, s) = length_data(be_u32)(data)?;
- Ok((r, std::str::from_utf8(s).unwrap()))
+ let end = s.iter().rposition(|b| b != &0u8).unwrap() + 1;
+ Ok((r, std::str::from_utf8(&s[0..end]).unwrap()))
}
#[derive(Debug, PartialEq)]
@@ -188,7 +188,7 @@ fn m_midi_part<'a>(data: &'a [u8]) -> IResult<&'a [u8], MMidiPart<'a>> {
fn node_value<'a>(class: &str, data: &'a [u8]) -> IResult<&'a [u8], NodeValue<'a>> {
match class {
- "PAppVersion\0" => {
+ "PAppVersion" => {
let (r, appver) = p_appversion(&data)?;
Ok((r, NodeValue::Version(appver)))
},