wip cow
This commit is contained in:
parent
2bc62edba8
commit
a7efac53c2
4 changed files with 48 additions and 1 deletions
|
@ -3,4 +3,5 @@ use nom;
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub enum IMFError<'a> {
|
||||
Segment(nom::Err<nom::error::Error<&'a [u8]>>),
|
||||
ExtractFields(nom::Err<nom::error::Error<&'a str>>),
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
pub mod model;
|
||||
|
||||
// Generic
|
||||
mod whitespace;
|
||||
pub mod whitespace;
|
||||
mod words;
|
||||
mod quoted;
|
||||
mod misc_token;
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
use std::borrow::Cow;
|
||||
use nom::{
|
||||
IResult,
|
||||
character::complete::space1,
|
||||
bytes::complete::is_not,
|
||||
combinator::{all_consuming, recognize},
|
||||
multi::{fold_many0, many0, many1},
|
||||
sequence::{pair, tuple},
|
||||
};
|
||||
|
||||
use crate::multipass::guess_charset::GuessCharset;
|
||||
use crate::error::IMFError;
|
||||
use crate::fragments::whitespace;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ExtractFields<'a> {
|
||||
pub raw_header: Cow<'a, str>,
|
||||
pub fields: Vec<&'a str>,
|
||||
pub body: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<GuessCharset<'a>> for ExtractFields<'a> {
|
||||
type Error = IMFError<'a>;
|
||||
|
||||
fn try_from(gcha: GuessCharset<'a>) -> Result<Self, Self::Error> {
|
||||
let mut ef = ExtractFields { fields: vec![], raw_header: gcha.header, body: gcha.body };
|
||||
let (_, fields) = all_consuming(many0(foldable_line))(ef.raw_header).map_err(|e| IMFError::ExtractFields(e))?;
|
||||
panic!();
|
||||
//ef.fields = fields;
|
||||
//Ok(ef)
|
||||
}
|
||||
}
|
||||
|
||||
/// ```abnf
|
||||
/// fold_line = !crlf *(1*(crlf WS) !crlf) crlf
|
||||
/// ```
|
||||
fn foldable_line<'a>(input: Cow<'a, str>) -> IResult<Cow<'a, str>, Cow<'a, str>> {
|
||||
recognize(tuple((
|
||||
is_not("\r\n"),
|
||||
many0(pair(
|
||||
many1(pair(whitespace::perm_crlf, space1)),
|
||||
is_not("\r\n"))),
|
||||
whitespace::perm_crlf
|
||||
)))(input)
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod segment;
|
||||
pub mod guess_charset;
|
||||
pub mod extract_fields;
|
||||
|
|
Loading…
Reference in a new issue