What should an escape character do if the next character does not need escaping?

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?

+3
source share
2 answers

I voted for the first decision. This makes it easy to form strings: if you don’t know if the character has special meaning in your context, just avoid it. It will not hurt.

+5

, , . , . Perl , , .

++, 4: , . "" , , .

Windows API, - ++, , , , , .

+1

Source: https://habr.com/ru/post/1768272/


All Articles