MCPcopy Index your code
hub / github.com/endbasic/endbasic / parse_propline

Function parse_propline

cli/src/propline.rs:43–78  ·  view source on GitHub ↗

Parses a propline from `line`. Returns an error if `line` looks like a propline but its contents are invalid.

(line: &str)

Source from the content-addressed store, hash-verified

41///
42/// Returns an error if `line` looks like a propline but its contents are invalid.
43fn parse_propline(line: &str) -> io::Result<PropLine> {
44 let without_comment = match line.strip_prefix("' ") {
45 Some(line) => Some(line),
46 None => {
47 if line.len() <= 4 {
48 None
49 } else {
50 let token = line[0..4].to_ascii_lowercase();
51 if token == "rem " { Some(&line[4..]) } else { None }
52 }
53 }
54 };
55 let Some(payload) = without_comment else {
56 return Ok(PropLine::default());
57 };
58
59 let Some(payload) = payload.strip_prefix("endbasic cli: ") else {
60 return Ok(PropLine::default());
61 };
62
63 let Some(console_spec) = payload.strip_prefix("console=") else {
64 return Err(io::Error::new(
65 io::ErrorKind::InvalidInput,
66 format!("Invalid EndBASIC propline: {}", line),
67 ));
68 };
69
70 if console_spec.is_empty() {
71 return Err(io::Error::new(
72 io::ErrorKind::InvalidInput,
73 "Invalid EndBASIC propline: missing console specification",
74 ));
75 }
76
77 Ok(PropLine { console_spec: Some(console_spec.to_owned()) })
78}
79
80/// Extracts the property line from `path` if present.
81pub fn extract_propline<P: AsRef<Path>>(path: P) -> io::Result<PropLine> {

Callers 1

extract_proplineFunction · 0.85

Calls 2

lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected