This commit is contained in:
PoiScript 2019-01-10 20:58:13 +08:00
parent a85efe2056
commit 6f7fa9c920
16 changed files with 622 additions and 229 deletions

View file

@ -1,7 +1,8 @@
pub struct Emphasis;
impl Emphasis {
pub fn parse(src: &str, marker: u8) -> Option<(&'_ str, usize)> {
// TODO: return usize instead of Option<usize>
pub fn parse(src: &str, marker: u8) -> Option<usize> {
expect!(src, 1, |c: u8| !c.is_ascii_whitespace());
let mut lines = 0;
@ -23,24 +24,19 @@ impl Emphasis {
|| ch == b'!'
|| ch == b'?'
|| ch == b'\''
|| ch == b'\n'
|| ch == b')'
|| ch == b'}');
}
Some((&src[1..end], end + 1))
Some(end - 1)
}
}
#[test]
fn parse() {
assert_eq!(
Emphasis::parse("*bold*", b'*').unwrap(),
("bold", "*bold*".len())
);
assert_eq!(
Emphasis::parse("*bo\nld*", b'*').unwrap(),
("bo\nld", "*bo\nld*".len())
);
assert_eq!(Emphasis::parse("*bold*", b'*').unwrap(), "bold".len());
assert_eq!(Emphasis::parse("*bo\nld*", b'*').unwrap(), "bo\nld".len());
assert!(Emphasis::parse("*bold*a", b'*').is_none());
assert!(Emphasis::parse("*bold*", b'/').is_none());
assert!(Emphasis::parse("*bold *", b'*').is_none());