pub fn from_str(text: &str) -> Result<Self, CigarError> {
        lazy_static! {
            // regex for a cigar string operation
            static ref OP_RE: Regex = Regex::new("^(?P<n>[0-9]+)(?P<op>[MIDNSHP=X])").unwrap();
        }
        let mut inner = Vec::new();
        let mut i = 0;
        while i < text.len() {
            if let Some(caps) = OP_RE.captures(&text[i..]) {
                let n = &caps["n"];
                let op = &caps["op"];
                i += n.len() + op.len();
                let n = u32::from_str(n)
                    .map_err(|_| CigarError::UnexpectedOperation("expected integer".to_owned()))?;
                inner.push(match op {
                    "M" => Cigar::Match(n),
                    "I" => Cigar::Ins(n),
                    "D" => Cigar::Del(n),
                    "N" => Cigar::RefSkip(n),
                    "H" => Cigar::HardClip(n),
                    "S" => Cigar::SoftClip(n),
                    "P" => Cigar::Pad(n),
                    "=" => Cigar::Equal(n),
                    "X" => Cigar::Diff(n),
                    op => {
                        return Err(CigarError::UnexpectedOperation(format!(
                            "operation {} not expected",
                            op
                        )))
                    }
                });
            } else {
                return Err(CigarError::UnexpectedOperation(
                    "expected cigar operation [0-9]+[MIDNSHP=X]".to_owned(),
                ));
            }
        }

        Ok(CigarString(inner))
    }
/// Create a CigarString from given str.
Create a CigarString from given str.
Create a CigarString from given str .
pub fn from_str(text: &str) -> Result<Self, CigarError> {
        lazy_static! {
            // regex for a cigar string operation
            static ref OP_RE: Regex = Regex::new("^(?P<n>[0-9]+)(?P<op>[MIDNSHP=X])").unwrap();
        }
        let mut inner = Vec::new();
        let mut i = 0;
        while i < text.len() {
            if let Some(caps) = OP_RE.captures(&text[i..]) {
                let n = &caps["n"];
                let op = &caps["op"];
                i += n.len() + op.len();
                let n = u32::from_str(n)
                    .map_err(|_| CigarError::UnexpectedOperation("expected integer".to_owned()))?;
                inner.push(match op {
                    "M" => Cigar::Match(n),
                    "I" => Cigar::Ins(n),
                    "D" => Cigar::Del(n),
                    "N" => Cigar::RefSkip(n),
                    "H" => Cigar::HardClip(n),
                    "S" => Cigar::SoftClip(n),
                    "P" => Cigar::Pad(n),
                    "=" => Cigar::Equal(n),
                    "X" => Cigar::Diff(n),
                    op => {
                        return Err(CigarError::UnexpectedOperation(format!(
                            "operation {} not expected",
                            op
                        )))
                    }
                });
            } else {
                return Err(CigarError::UnexpectedOperation(
                    "expected cigar operation [0-9]+[MIDNSHP=X]".to_owned(),
                ));
            }
        }
        Ok(CigarString(inner))
    }
pub fn from_str ( text : & str ) -> Result < Self , CigarError > { lazy_static ! { // regex for a cigar string operation static ref OP_RE Regex Regex new ( " " ) unwrap ( ) } let mut inner = Vec :: new ( ) ; let mut i = 0 ; while i < text . len ( ) { if let Some ( caps ) = OP_RE . captures ( & text [ i .. ] ) { let n = & caps [ " " ] ; let op = & caps [ " " ] ; i += n . len ( ) + op . len ( ) ; let n = u32 :: from_str ( n ) . map_err ( | _ | CigarError :: UnexpectedOperation ( " " . to_owned ( ) ) ) ? ; inner . push ( match op { " " => Cigar :: Match ( n ) , " " => Cigar :: Ins ( n ) , " " => Cigar :: Del ( n ) , " " => Cigar :: RefSkip ( n ) , " " => Cigar :: HardClip ( n ) , " " => Cigar :: SoftClip ( n ) , " " => Cigar :: Pad ( n ) , " " => Cigar :: Equal ( n ) , " " => Cigar :: Diff ( n ) , op => { return Err ( CigarError :: UnexpectedOperation ( format ! ( " " op ) ) ) } } ) ; } else { return Err ( CigarError :: UnexpectedOperation ( " " . to_owned ( ) , ) ) ; } } Ok ( CigarString ( inner ) ) }
Create a CigarString from given str.
Create a CigarString from given str .
text
&str
text
&str