From 856581e43af0261fd396f6268b9cf11cd7fe2b30 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Thu, 4 Apr 2024 01:01:03 +1300 Subject: Re-work literals to only begin with a double-quote and not end with one --- src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 74cb73d..14ff4eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ enum Error { DuplicateCategory(OsString), BadPath(PathBuf), EmptyOption, + InvalidLiteral(String), } impl fmt::Display for Error { @@ -54,6 +55,8 @@ impl fmt::Display for Error { write!(f, "failed to parse path: {:?}", p), Error::EmptyOption => write!(f, "multi-option variable had an empty option"), + Error::InvalidLiteral(s) => + write!(f, "literal option contains an inner quote-mark: {}", s), } } } @@ -100,13 +103,11 @@ impl DropIn { return Ok(DropIn::OneOf(options)) } - // TODO: investigate viability of supporting escape sequences - if let Some(inner) = text.strip_prefix('"') - .and_then(|s| s.strip_suffix('"')) - { - // REVIEW: investigate interactions of filenames that contain '"' - if !inner.contains('"') { - return Ok(DropIn::Literal(inner.to_string())); + if let Some(lit) = text.strip_prefix('"') { + if lit.contains('"') { + return Err(Error::InvalidLiteral(text.to_string())); + } else { + return Ok(DropIn::Literal(lit.to_string())); } } -- cgit v1.2.1