Some ASCII code utilities, to process sequences of ASCII code bytes as
easily as strings.
Examples:
(bytes= buffer #.(ascii-bytes "HELO ") :end1 (min 5 (length buffer)))
(bytes= (read-ascii-line) #"HELO " :end1 (min 5 (length buffer)))
License:
AGPL3
Copyright Pascal J. Bourguignon 2006 - 2015
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program.
If not, see <http://www.gnu.org/licenses/>
|
*ascii-characters* |
variable |
A string containing all the ASCII characters in lexical order.
Initial value: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
*hexadecimal-digits* |
variable |
A string contaiing the hexadecimal digits (lower case letters) in order.
Initial value: 0123456789abcdef
|
*newline* |
variable |
(OR (MEMBER :CRLF :CR :LF)
(CONS (MEMBER :CRLF :CR :LF) (MEMBER :CRLF :CR :LF :ANY))
The encoding used for #newline for output and for input.
If it's a keyword, it's used for both output and input.
If it's a CONS cell, the CAR specifies the newline encoding for output
and the CDR specifies the newline encoding for input (it may be :ANY to
accept any of CR-LF, CR or LF; LF-CR would read as two newlines).
Initial value: CRLF
|
(ack) |
function |
ACKNOWLEDGE
ACK is transmitted by a receiver as an affirmative response
to the sender. The use of ACK is defined in ISO 1745.
|
ack |
constant |
ACKNOWLEDGE
Initial value: 6
|
(ascii-bytes string &key newline start end) |
function |
RETURN: A byte vector containing the ASCII codes of the characters in
the string.
Only printable character and #newline are accepted in the string.
#newline is translated to either CR+LF, CR, or LF according to the
NEWLINE parameter.
NEWLINE: (member :crlf :cr :lf) ; the default is *NEWLINE*.
|
(ascii-code ch) |
function |
RETURN: The ASCII code of the character ch, or raise an error if the character
has no ascii code.
Only printable characters are accepted. No control code.
|
(ascii-control-code-p code) |
function |
RETURN: Whether CODE is an ASCII control code.
|
(ascii-dispatch-macro stream sub-char argument) |
function |
DO: Read a string and converts it to an ASCII byte sequence.
ARGUMENT: If NIL, #newline are encoded according to *NEWLINE*.
If 0, #newline are encoded to CR-LF.
If 1, #newline are encoded to LF.
If 2, #newline are encoded to CR.
Otherwise an error is issued.
SUB-CHAR: If it is #" then it's considered the start of the string,
otherwise we expect to read a full string next.
This allow to set dispatch macro characters for: #"abc" or #Y"abc"
EXAMPLES:
(set-dispatch-macro-character ## #Y (function ascii-dispatch-macro) *readtable*)
(set-dispatch-macro-character ## #" (function ascii-dispatch-macro) *readtable*)
|
(ascii-format destination ctrl-string &rest arguments) |
function |
DO: Format the CTRL-STRING and the ARGUMENTS with FORMAT,
convert the resulting string to a vector of ASCII
bytes and send it to the DESTINATION.
RETURN: NIL if DESTINATION is not NIL, a byte vector otherwise.
DESTINATION: T -> *STANDARD-OUTPUT*
NIL -> A vector of bytes is returned.
STREAM -> An output binary stream to which the bytes are written.
CTRL-STRING: A FORMAT control string (contaiing only characters in
the ASCII character set).
ARGUMENTS: Arguments to be formated with FORMAT.
SEE ALSO: FORMAT
|
(ascii-printable-code-p code) |
function |
RETURN: Whether CODE is the code of an ASCII printable character.
|
(ascii-string bytes &key newline start end) |
function |
DO: Converts the ASCII bytes to a string. If there are control codes,
an error is signaled.
RETURN: A string containing the characters encoded in the ASCII bytes.
NEWLINE: (member :crlf :cr :lf :any) ; the default is *NEWLINE*.
If lone CR or LF are present, then an error is signaled.
START: index of the first byte to be converted.
END: index beyond the last byte to be converted.
|
(bel) |
function |
BELL
BEL is used when there is a need to call for attention; it
may control alarm or attention devices.
|
bel |
constant |
BELL
Initial value: 7
|
(bs) |
function |
BACKSPACE
BS causes the active data position to be moved one character
position in the data component in the direction opposite to that of
the implicit movement. The direction of the implicit movement depends
on the parameter value of SELECT IMPLICIT MOVEMENT DIRECTION (SIMD).
|
bs |
constant |
BACKSPACE
Initial value: 8
|
(bytes/= v1 v2 &key start1 start2 end1 end2) |
function |
like string/=, but for byte vectors.
|
(bytes< v1 v2 &key start1 start2 end1 end2) |
function |
like string<, but for byte vectors.
|
(bytes<= v1 v2 &key start1 start2 end1 end2) |
function |
like string<=, but for byte vectors.
|
(bytes= v1 v2 &key start1 start2 end1 end2) |
function |
like string=, but for byte vectors.
|
(bytes> v1 v2 &key start1 start2 end1 end2) |
function |
like string<, but for byte vectors.
|
(bytes>= v1 v2 &key start1 start2 end1 end2) |
function |
like string>=, but for byte vectors.
|
(can) |
function |
CANCEL
CAN is used to indicate that the data preceding it in the
data stream is in error. As a result, this data shall be ignored. The
specific meaning of this control function shall be defined for each
application and/or between sender and recipient.
|
can |
constant |
CANCEL
Initial value: 24
|
(code-ascii code) |
function |
RETURN: The character corresponding to the given ASCII code.
Only codes for printable characters are accepted,
and both CR and LF are mapped to #newline.
|
(code-ascii-digit-p code) |
function |
RETURN: The decimal digit value of the character encoded by the ASCII CODE,
or NIL if CODE is not the ASCII code of a digit character.
|
(cr) |
function |
CARRIAGE RETURN
The effect of CR depends on the setting of the DEVICE
COMPONENT SELECT MODE (DCSM) and on the parameter value of SELECT
IMPLICIT MOVEMENT DIRECTION (SIMD). If the DEVICE COMPONENT SELECT
MODE (DCSM) is set to PRESENTATION and with the parameter value of
SIMD equal to 0, CR causes the active presentation position to be
moved to the line home position of the same line in the presentation
component. The line home position is established by the parameter
value of SET LINE HOME (SLH). With a parameter value of SIMD equal to
1, CR causes the active presentation position to be moved to the line
limit position of the same line in the presentation component. The
line limit position is established by the parameter value of SET LINE
LIMIT (SLL). If the DEVICE COMPONENT SELECT MODE (DCSM) is set to DATA
and with a parameter value of SIMD equal to 0, CR causes the active
data position to be moved to the line home position of the same line
in the data component. The line home position is established by the
parameter value of SET LINE HOME (SLH). With a parameter value of SIMD
equal to 1, CR causes the active data position to be moved to the line
limit position of the same line in the data component. The line limit
position is established by the parameter value of SET LINE LIMIT
(SLL).
|
cr |
constant |
CARRIAGE RETURN
Initial value: 13
|
(dc1) |
function |
DEVICE CONTROL ONE
DC1 is primarily intended for turning on or starting an
ancillary device. If it is not required for this purpose, it may be
used to restore a device to the basic mode of operation (see also DC2
and DC3), or any other device control function not provided by other
DCs.
|
dc1 |
constant |
DEVICE CONTROL ONE
Initial value: 17
|
(dc2) |
function |
DEVICE CONTROL TWO
DC2 is primarily intended for turning on or starting an
ancillary device. If it is not required for this purpose, it may be
used to set a device to a special mode of operation (in which case DC1
is used to restore the device to the basic mode), or for any other
device control function not provided by other DCs.
|
dc2 |
constant |
DEVICE CONTROL TWO
Initial value: 18
|
(dc3) |
function |
DEVICE CONTROL THREE
DC3 is primarily intended for turning off or stopping an
ancillary device. This function may be a secondary level stop, for
example wait, pause, stand-by or halt (in which case DC1 is used to
restore normal operation). If it is not required for this purpose, it
may be used for any other device control function not provided by
other DCs.
|
dc3 |
constant |
DEVICE CONTROL THREE
Initial value: 19
|
(dc4) |
function |
DEVICE CONTROL FOUR
DC4 is primarily intended for turning off, stopping or
interrupting an ancillary device. If it is not required for this
purpose, it may be used for any other device control function not
provided by other DCs.
|
dc4 |
constant |
DEVICE CONTROL FOUR
Initial value: 20
|
decoding-error |
condition |
The condition denoting a decoding error.
Class precedence list: DECODING-ERROR ERROR SERIOUS-CONDITION CONDITION STANDARD-OBJECT T
Class init args: CODE CODING-SYSTEM MESSAGE
|
(decoding-error-code x) |
generic-function |
The code that corresponds to no character.
|
(decoding-error-coding-system x) |
generic-function |
A keyword denoting the coding system which cannot decode the code.
|
(decoding-error-message x) |
generic-function |
The error message.
|
del |
constant |
-- delete
Initial value: 127
|
(dle) |
function |
DATA LINK ESCAPE
DLE is used exclusively to provide supplementary transmission
control functions. The use of DLE is defined in ISO 1745.
|
dle |
constant |
DATA LINK ESCAPE
Initial value: 16
|
(em) |
function |
END OF MEDIUM
EM is used to identify the physical end of a medium, or the
end of the used portion of a medium, or the end of the wanted portion
of data recorded on a medium.
|
em |
constant |
END OF MEDIUM
Initial value: 25
|
encoding-error |
condition |
The condition denoting an encoding error.
Class precedence list: ENCODING-ERROR ERROR SERIOUS-CONDITION CONDITION STANDARD-OBJECT T
Class init args: CHARACTER CODING-SYSTEM MESSAGE
|
(encoding-error-character x) |
generic-function |
The character that cannot be encoded.
|
(encoding-error-coding-system x) |
generic-function |
A keyword denoting the coding system which cannot encode the character.
|
(encoding-error-message x) |
generic-function |
The error message.
|
(enq) |
function |
ENQUIRY
ENQ is transmitted by a sender as a request for a response
from a receiver. The use of ENQ is defined in ISO 1745.
|
enq |
constant |
ENQUIRY
Initial value: 5
|
(eot) |
function |
END OF TRANSMISSION
EOT is used to indicate the conclusion of the transmission of
one or more texts. The use of EOT is defined in ISO 1745.
|
eot |
constant |
END OF TRANSMISSION
Initial value: 4
|
(esc) |
function |
ESCAPE
ESC is used for code extension purposes. It causes the
meanings of a limited number of bit combinations following it in the
data stream to be changed. The use of ESC is defined in Standard
ECMA-35.
|
esc |
constant |
ESCAPE
Initial value: 27
|
(etb) |
function |
END OF TRANSMISSION BLOCK
ETB is used to indicate the end of a block of data where the
data are divided into such blocks for transmission purposes. The use
of ETB is defined in ISO 1745.
|
etb |
constant |
END OF TRANSMISSION BLOCK
Initial value: 23
|
(etx) |
function |
END OF TEXT
ETX is used to indicate the end of a text. The use of ETX is
defined in ISO 1745.
|
etx |
constant |
END OF TEXT
Initial value: 3
|
(ff) |
function |
FORM FEED
FF causes the active presentation position to be moved to the
corresponding character position of the line at the page home position
of the next form or page in the presentation component. The page home
position is established by the parameter value of SET PAGE HOME
(SPH).
|
ff |
constant |
FORM FEED
Initial value: 12
|
fs |
constant |
IS4 -- file separator
Initial value: 28
|
gs |
constant |
IS3 -- group separator
Initial value: 29
|
(ht) |
function |
CHARACTER TABULATION
HT causes the active presentation position to be moved to the
following character tabulation stop in the presentation component. In
addition, if that following character tabulation stop has been set by
TABULATION ALIGN CENTRE (TAC), TABULATION ALIGN LEADING EDGE (TALE),
TABULATION ALIGN TRAILING EDGE (TATE) or TABULATION CENTRED ON
CHARACTER (TCC), HT indicates the beginning of a string of text which
is to be positioned within a line according to the properties of that
tabulation stop. The end of the string is indicated by the next
occurrence of HT or CARRIAGE RETURN (CR) or NEXT LINE (NEL) in the
data stream.
|
ht |
constant |
CHARACTER TABULATION
Initial value: 9
|
(lf) |
function |
LINE FEED
If the DEVICE COMPONENT SELECT MODE (DCSM) is set to
PRESENTATION, LF causes the active presentation position to be moved
to the corresponding character position of the following line in the
presentation component. If the DEVICE COMPONENT SELECT MODE (DCSM) is
set to DATA, LF causes the active data position to be moved to the
corresponding character position of the following line in the data
component.
|
lf |
constant |
LINE FEED
Initial value: 10
|
(nak) |
function |
NEGATIVE ACKNOWLEDGE
NAK is transmitted by a receiver as a negative response to
the sender. The use of NAK is defined in ISO 1745.
|
nak |
constant |
NEGATIVE ACKNOWLEDGE
Initial value: 21
|
(nul) |
function |
NULL
NUL is used for media-fill or time-fill. NUL characters may
be inserted into, or removed from, a data stream without affecting the
information content of that stream, but such action may affect the
information layout and/or the control of equipment.
|
nul |
constant |
NULL
Initial value: 0
|
(read-ascii-line stream &optional eof-error eof-value newline) |
function |
newline: (member :crlf :cr :lf) ; the defaultl is :CRLF since that's what's
used in internet binary protocols using ascii.
|
rs |
constant |
IS2 -- record separator
Initial value: 30
|
(si) |
function |
SHIFT-IN
SI is used for code extension purposes. It causes the
meanings of the bit combinations following it in the data stream to be
changed. The use of SI is defined in Standard ECMA-35.
|
si |
constant |
SHIFT-IN
Initial value: 15
|
(so) |
function |
SHIFT-OUT
SO is used for code extension purposes. It causes the
meanings of the bit combinations following it in the data stream to be
changed. The use of SO is defined in Standard ECMA-35.
|
so |
constant |
SHIFT-OUT
Initial value: 14
|
(soh) |
function |
START OF HEADING
SOH is used to indicate the beginning of a heading. The use
of SOH is defined in ISO 1745.
|
soh |
constant |
START OF HEADING
Initial value: 1
|
sp |
constant |
Code of ASCII Character SPACE
Initial value: 32
|
(stx) |
function |
START OF TEXT
STX is used to indicate the beginning of a text and the end of a
heading. The use of STX is defined in ISO 1745.
|
stx |
constant |
START OF TEXT
Initial value: 2
|
(sub) |
function |
SUBSTITUTE
SUB is used in the place of a character that has been found to be
invalid or in error. SUB is intended to be introduced by automatic
means.
|
sub |
constant |
SUBSTITUTE
Initial value: 26
|
(syn) |
function |
SYNCHRONOUS IDLE
SYN is used by a synchronous transmission system in the absence of
any other character (idle condition) to provide a signal from which
synchronism may be achieved or retained between data terminal
equipment. The use of SYN is defined in ISO 1745.
|
syn |
constant |
SYNCHRONOUS IDLE
Initial value: 22
|
us |
constant |
IS1 -- unit separator
Initial value: 31
|
(vt) |
function |
LINE TABULATION
VT causes the active presentation position to be moved in the
presentation component to the corresponding character position on the
line at which the following line tabulation stop is set.
|
vt |
constant |
LINE TABULATION
Initial value: 11