Skip to content

Commit

Permalink
Support --- as document start
Browse files Browse the repository at this point in the history
Signed-off-by: Gris Ge <[email protected]>
  • Loading branch information
cathay4t committed Dec 27, 2024
1 parent f0b5263 commit d8fc946
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/char_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ impl<'s> CharsIter<'s> {
}
}
}

pub(crate) fn as_str(&self) -> &str {
self.iter.as_str()
}
}
9 changes: 9 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_de_bool() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn test_de_unsign_number() -> Result<(), Box<dyn std::error::Error>> {
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")?);

Expand All @@ -56,6 +56,7 @@ fn test_de_struct() -> Result<(), Box<dyn std::error::Error>> {
}

let yaml_str = r#"
---
uint_a: 500
str_b: "abc"
bar:
Expand Down

0 comments on commit d8fc946

Please sign in to comment.