diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2024-04-04 01:01:03 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2024-04-04 01:03:22 +1300 |
| commit | 856581e43af0261fd396f6268b9cf11cd7fe2b30 (patch) | |
| tree | a3792fc7cfbc995f723264e8f03a9ba2d264a472 | |
| parent | 82b522fcebfbcb6e464d7b87cb017b110368b70c (diff) | |
Re-work literals to only begin with a double-quote and not end with one
| -rw-r--r-- | src/main.rs | 15 | ||||
| -rw-r--r-- | test_data/sentences.txt | 5 |
2 files changed, 11 insertions, 9 deletions
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())); } } diff --git a/test_data/sentences.txt b/test_data/sentences.txt index 7c48dbf..e7efa26 100644 --- a/test_data/sentences.txt +++ b/test_data/sentences.txt @@ -12,5 +12,6 @@ This sentence uses 10 identical variables: %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %% This sentence uses either type a or b: %%a|b%% This sentence uses a variable, then either type a or the same variable: %%?x%% %%a|?x%% This sentence uses four completely random types: %%?%% %%?%% %%?%% %%?%% -This sentence chooses the word 'foo' or 'bar': %%"foo"|"bar"%% -This sentence chooses the word 'foo' or a word from type c: %%"foo"|c%% +This sentence chooses the word 'foo' or 'bar': %%"foo|"bar%% +This sentence chooses the word 'foo' or a word from type c: %%"foo|c%% +Intentionally malformed: %%"fo|"o%% |
