[−][src]Function sorer::parsers::parse_line
pub fn parse_line(i: &[u8]) -> Option<Vec<Data>>
Parses a row of SoR
data, i
(as a &[u8]
), into a Option<Vec<Data>>
Returning Some
if i
was a valid sor row, None
otherwise. It parses
using the most conservative precedence possible. Types bool
are parsed
first, then int
, then float
, then string
.
If a field is invalid, returns a None
.
Examples
use sorer::parsers::parse_line; use sorer::dataframe::Data; let i = b"< 1 > < hi >< +2.2 >"; assert_eq!(Some(vec![Data::Bool(true), Data::String(String::from("hi")), Data::Float(2.2)]), parse_line(i));
Safety
This function calls std::str::from_utf8_unchecked
, meaning that it does not check that the
bytes passed to it are valid UTF-8. If this constraint is violated, undefined behavior results,
as the rest of Rust assumes that &strs are valid UTF-8.
Since SoR
files are guaranteed to only contain valid C++ strings, and thus only valid utf-8
,
then this constraint only applies to consumers of the crate and not users of the SoRer
executable.