blob: ee99efa1593ab34fa5a838f55e2d3d9da6ed176e [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001CONCEPT
2 character escape codes
3
4DESCRIPTION
5 Character escape codes are used to represent some common
6 special characters that would be awkward or impossible to
7 enter in the source program directly. The escape characters
8 come in two varieties: 'character escapes', which can be
9 used to represent some particular formatting and special
10 characters, and 'numeric escapes', which allow a character to
11 be specified by its numeric encoding.
12
13 Escapes begin always with a backslash '\'. If the following
14 characters could not be treated as a valid escape the backslash
15 is merely ignored.
16
17 The following character escapes are available in LPC (the code
18 may differ from platform to platform):
19
20 \a Code 007 Bell
21 \b Code 008 Backspace
22 \e Code 027 Escape
23 \f Code 012 Formfeed
24 \n Code 010 Newline
25 \r Code 013 Carriage-Return
26 \t Code 009 Tabulator
27 \\ Code 092 Backslash itself
28 \' Code 039 Single quote
29 \" Code 034 Double quote
30
31 The single quote may appear without preceding backslash in character
32 constants, and the double quote may appear without a backslash in
33 string constants.
34
35 The numeric escapes could be used to express a character directly
36 by its code in binary, octal, decimal or hexadecimal notation.
37
Zesstra7ea4a032019-11-26 20:11:40 +010038 \0b Beginning of binary notation
39 \0o Beginning of octal notation
40 \0x Beginning of hexadecimal notation
41 \x Beginning of hexadecimal notation
42 \u, \U Beginning of extended hexadecimal notation
MG Mud User88f12472016-06-24 23:31:02 +020043
44 A backslash followed by a digit ([0-9]) which does not map to one
45 of the above starts an escape in decimal notation.
46
47 A numeric escape terminates when N digits have been used up or
48 when the first character that is not a valid digit in that
Zesstra7ea4a032019-11-26 20:11:40 +010049 notation is encountered. N is 2 for hexadeximals with \0x and \x,
50 3 for decimals and octals, 4 for hexadecimals with \u,
51 8 for binarys and for hexadecimals with \U.
MG Mud User88f12472016-06-24 23:31:02 +020052
53 If the specified code is greater than 255 a warning is issued and
Zesstra7ea4a032019-11-26 20:11:40 +010054 the value modulo 256 is used (except for \u and \U).
MG Mud User88f12472016-06-24 23:31:02 +020055
56EXAMPLES
57 Put a newline at the end of user output
58 "You enter.\n"
59
60 Alert the user
61 "Beeep.\a Wake up\n"
62
63 Put a double quote in a string
64 "You say \"hello\"\n"
65
66 Write the line from above
67 "\"You say \\\"hello\\\"\\n\""
68
69 Put a single quote in a string
70 "You say 'hello'\n"
71
72 Some forms to write "abcde"
73 "abcde"
74 "ab\99de" (with c's code being 99)
75 "ab\099de"
76 "ab\x63de" (99 = 0x63)
77 "ab\0x63de"
78
79 The following string consists of two characters
80 "\0111" (\011 and 1)
81
82 The following string consists of three characters
83 "\0o090" (\000 and 9 and 0)