aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 6eb105b..dfeea93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,7 +21,8 @@ use cubase_project::*;
use nom::{
bytes::complete::*,
- multi::{length_data, many1},
+ combinator::map,
+ multi::{length_data, length_value, many1},
number::complete::*,
sequence::tuple,
Finish,
@@ -37,10 +38,11 @@ use std::{
/// 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.
+///
+/// We assume strings to be UTF-8 encoded.
fn cmstring(data: &[u8]) -> IResult<&[u8], &str> {
- let (r, s) = length_data(be_u32)(data)?;
- let end = s.iter().rposition(|b| b != &0u8).unwrap() + 1;
- Ok((r, std::str::from_utf8(&s[0..end]).unwrap()))
+ let strdata = length_value(be_u32, take_till(|c| c == b'\0'));
+ map(strdata, |s| std::str::from_utf8(s).unwrap())(data)
}
/**