The characters are escaping!
April 23, 2007 Leave a comment
One of the things I’ve noticed in the main chat of the public DC development hub is that people seem to have a trouble understanding the escape sequences and command ending character in ADC.
Certain characters in ADC are used for command termination and command delimitation. This mean that these characters need to be escaped in commands where these characters might come up in the message one side is trying to relay. Normal messaging is the most obvious that is affected by these escapes.
The following characters are, in effect, those kind of characters;
A space (” “) – In ADC; “\s”
A new line – In ADC; “\n”
A backslash (“\”) – In ADC; “\\”
The character that has been chosen for escaping characters is the backslash character, as one might see above. Any other type of escape sequence is restricted.
The character for ending a command is ‘\n’. And the answer is ‘no’ to your first question; “But that’s the same as for a plain new line?!”.
The new line representation is not one character, but two. The backslash and a ‘n’. The termination character is the character we see as a new line; ‘\n’. This character can be written differently in different languages. The ADC draft say ‘0x0a’. (Try it in your own language. It’s the same as if you wrote ‘\n’.
When you’re writing your client, hub, bot or whatnot, your language probably have a restriction where you need to escape backslashes in your code. This mean that when coding, you’re supposed to look for the string “\\s” to search for the visual character of a space. And with “\\”, it will become “\\\\”. (As the first backslash esacpe the second, and the third escape the forth.)
So, if you’re ever going to learn anything from this post, learn this; “\n” is a sequence of two characters that represent a new line in a visual manner in ADC while ‘\n’ is one character that represent a new line in a command termination manner.