summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Unterwaditzer <markus@unterwaditzer.net>2018-01-11 20:36:35 +0100
committerMarkus Unterwaditzer <markus@unterwaditzer.net>2018-01-11 20:36:46 +0100
commitcaa9d74e3551d31433cc34e94441cdd0dc120416 (patch)
tree661436901b315943ac7479ce2861ed3755e82b0e
parent4cf79bbe7ac4ef74dfc0e6ee2a5770a8b00870a7 (diff)
add read_component
-rw-r--r--src/component.rs23
-rw-r--r--src/lib.rs1
2 files changed, 18 insertions, 6 deletions
diff --git a/src/component.rs b/src/component.rs
index 2c96a4a..897afa5 100644
--- a/src/component.rs
+++ b/src/component.rs
@@ -78,15 +78,26 @@ impl FromStr for Component {
/// Parse exactly one component. Trailing data generates errors.
pub fn parse_component(s: &str) -> Result<Component> {
+ let (rv, new_s) = try!(read_component(s));
+ if !new_s.is_empty() {
+ let s = format!("Trailing data: `{}`", new_s);
+ let kind = VObjectErrorKind::ParserError(s);
+ return Err(VObjectError::from_kind(kind));
+ }
+
+ Ok(rv)
+}
+
+/// Parse one component and return the rest of the string.
+pub fn read_component(s: &str) -> Result<(Component, &str)> {
let mut parser = Parser::new(s);
let rv = try!(parser.consume_component());
- if !parser.eof() {
- let s = format!("Trailing data: `{}`", &parser.input[parser.pos..]);
- let kind = VObjectErrorKind::ParserError(s);
- Err(VObjectError::from_kind(kind))
+ let new_s = if parser.eof() {
+ ""
} else {
- Ok(rv)
- }
+ &parser.input[parser.pos..]
+ };
+ Ok((rv, new_s))
}
/// Write a component to a String.
diff --git a/src/lib.rs b/src/lib.rs
index 38ea59a..737a41f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,6 +18,7 @@ pub mod icalendar;
pub use component::Component;
pub use component::parse_component;
+pub use component::read_component;
pub use component::write_component;
pub use property::Property;
pub use property::escape_chars;