In the application in which I work, there is a field in which a string can be entered.
Special characters in a string cause different things to be inserted when the string is evaluated, but these special characters may be preceded by an escape character (backslash) that causes the special character to be returned literally, rather than its special meaning.
Think of it as a regular expression: .matches any character, but \.matches a period.
What is the most intuitive thing that should happen when an escape character is followed by a character that does not need to be escaped? For example, it would be wiser to:
- the escape character "escapes" the literal as itself:
\fbecomes f("escaped f") - The control character is not an escape character, except for the special character:
\fremains\f - Error! Throw an exception because it is not valid to have an escape character that does not escape from it.
All this is possible and, in my opinion, justified. But what makes more sense and which is already most common in other languages?
source
share