diff --git a/src/char_iter.rs b/src/char_iter.rs index c3ef5fc..b605eea 100644 --- a/src/char_iter.rs +++ b/src/char_iter.rs @@ -67,4 +67,8 @@ impl<'s> CharsIter<'s> { } } } + + pub(crate) fn as_str(&self) -> &str { + self.iter.as_str() + } } diff --git a/src/token.rs b/src/token.rs index 07f6197..bfc1d6b 100644 --- a/src/token.rs +++ b/src/token.rs @@ -142,6 +142,15 @@ impl YamlToken { YAML_CHAR_SEQUENCE_ENTRY | YAML_CHAR_MAPPING_KEY | YAML_CHAR_MAPPING_VALUE => { + // We might be got `---` as document begin which we should + // ignore + if iter.as_str().starts_with("---") { + iter.next(); + iter.next(); + iter.next(); + continue; + } + let indicator = match c { YAML_CHAR_SEQUENCE_ENTRY => { YamlTokenData::BlockSequenceIndicator diff --git a/tests/from_str.rs b/tests/from_str.rs index 24df1c0..8d14931 100644 --- a/tests/from_str.rs +++ b/tests/from_str.rs @@ -30,7 +30,7 @@ fn test_de_bool() -> Result<(), Box> { #[test] fn test_de_unsign_number() -> Result<(), Box> { - assert_eq!(123114u32, rmsd_yaml::from_str("123114")?); + assert_eq!(123114u32, rmsd_yaml::from_str("\n---\n123114")?); assert_eq!(1234u16, rmsd_yaml::from_str("+1234")?); @@ -56,6 +56,7 @@ fn test_de_struct() -> Result<(), Box> { } let yaml_str = r#" + --- uint_a: 500 str_b: "abc" bar: