In any data format, the escaping mechanism must be escaped itself. The escape character is a special character.
For example, I want to display this text:
Ampersands are escaped like &
If I write this HTML as
<p>Ampersands are escaped like <code>&</code>
it will be displayed as:
Ampersands are escaped like &
So I actually need to write:
<p>Ampersands are escaped like <code>&amp;</code>
which displays correctly as:
Ampersands are escaped like &
In many languages, the backslash is an escape character. Then, the literal string C:\projects
will have to be escaped as C:\\projects
.
If a data format is supposed to be able to represent arbitrary data, it either needs a known length, or a delimiter. Handling known lengths is unwieldy in human-editable formats. But if we have a delimiter, it must be escapeable. So we need an escape mechanism, and the escape mechanism needs to escape itself. One minimal solution is to use the delimiter as the escape character. E.g. for a delimiter '
, the string don't do that
could be encoded as 'don''t do that'
.