MCPcopy Create free account
hub / github.com/RustCrypto/formats / next

Method next

base64ct/src/decoder.rs:508–544  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

506 type Item = Result<Line<'i>, Error>;
507
508 fn next(&mut self) -> Option<Result<Line<'i>, Error>> {
509 if let Some(line_width) = self.line_width {
510 let rest = match self.remaining.get(line_width..) {
511 None | Some([]) => {
512 if self.remaining.is_empty() {
513 return None;
514 } else {
515 let line = Line::new(self.remaining).trim_end();
516 self.remaining = &[];
517 return Some(Ok(line));
518 }
519 }
520 Some([CHAR_CR, CHAR_LF, rest @ ..]) => rest,
521 Some([CHAR_CR, rest @ ..]) => rest,
522 Some([CHAR_LF, rest @ ..]) => rest,
523 _ => {
524 // Expected a leading newline
525 return Some(Err(Error::InvalidEncoding));
526 }
527 };
528
529 let line = Line::new(&self.remaining[..line_width]);
530 self.remaining = rest;
531 Some(Ok(line))
532 } else if !self.remaining.is_empty() {
533 let line = Line::new(self.remaining).trim_end();
534 self.remaining = b"";
535
536 if line.is_empty() {
537 None
538 } else {
539 Some(Ok(line))
540 }
541 } else {
542 None
543 }
544 }
545}
546
547#[cfg(test)]

Callers 4

encodeMethod · 0.45
encodeMethod · 0.45
advance_lineMethod · 0.45
decoded_lenMethod · 0.45

Calls 3

trim_endMethod · 0.80
getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected