split_label

Function split_label 

Source
pub(crate) fn split_label(bytes: &[u8]) -> Option<(&str, &[u8])>
Expand description

Split a slice beginning with a type label as located in an encapsulation boundary. Returns the label as a &str, and slice beginning with the encapsulated text with leading ----- and newline removed.

This implementation follows the rules put forth in Section 2, which are stricter than those found in the ABNF grammar:

Labels are formally case-sensitive, uppercase, and comprised of zero or more characters; they do not contain consecutive spaces or hyphen-minuses, nor do they contain spaces or hyphen-minuses at either end.

We apply a slightly stricter interpretation:

  • Labels MAY be empty
  • Non-empty labels MUST start with an upper-case letter: 'A'..='Z'
  • The only allowable characters subsequently are 'A'..='Z' or WSP. (NOTE: this is an overly strict initial implementation and should be relaxed)
  • Whitespace MUST NOT contain more than one consecutive WSP character