An application I'm working on has a field where a string can be entered.
Special characters in the string cause different things to be inserted when the string is evaluated, but these special characters can be preceded by an escape character (a backslash) which cause the special character to be output literally rather than its special meaning.
Think of it as similar to a regular expression: .
matches any character but \.
matches a dot.
What is the most intuitive thing to happen when the escape character is followed by a character which doesn't need escaping? For example, would it make more sense that:
- The escape character "escapes" the literal as itself:
\f
becomesf
("an escaped f") - The escape character isn't an escape character unless it's followed by a special character:
\f
remains as\f
- Error! Throw an exception because the it's invalid to have an escape character not escaping anything
All of these are possible and in my opinion justifiable. But which makes more sense, and which is already most common in other languages?