strings: add functions to encode/decode strings into byte sequences

API copied from sbcl.
This commit is contained in:
Marius Gerbershagen 2021-02-27 19:51:50 +01:00
parent 43be4f6d3e
commit 55af7bae85
5 changed files with 114 additions and 1 deletions

View file

@ -2301,6 +2301,15 @@ Evaluates FORMs in order from left to right. If any FORM evaluates to non-
NIL, quits and returns that (single) value. If the last FORM is reached,
returns whatever values it returns.")
(docfun ext::octets-to-string function (input &key
(external-format :default)
(start 0)
(end nil)) "
Decode a sequence of octets into a string according to the given
external format. The bounding index designators start and end optionally
denote a subsequence to be decoded.
")
(docfun output-stream-p function (stream) "
Returns T if STREAM can handle output operations; NIL otherwise.")
@ -3014,6 +3023,17 @@ Similar to STRING>=, but ignores cases.")
Returns a copy of STRING with the specified characters removed from the right
end. CHAR-SPEC must be a sequence of characters.")
(docfun ext::string-to-octets function (input &key
(external-format :default)
(start 0)
(end nil)
(null-terminate nil)) "
Encode a string into a sequence of octets according to the given
external format. The bounding index designators start and end
optionally denote a subsequence to be encoded. If null-terminate is
true, add a terminating null byte.
")
(docfun si::string-to-object function (string) "
ECL specific.
Equivalent to (READ-FROM-STRING STRING), but is much faster.")

View file

@ -67,6 +67,29 @@ The counterpart of the previous function is @coderef{ecl_char_set}, which implem
Both functions check the type of their arguments and verify that the indices do not exceed the string boundaries. Otherwise they signal a @code{serious-condition}.
@end deftypefun
@subsubsection Converting Unicode strings
Converting between different encodings. See @ref{Streams - External formats} for a list of supported encodings (external formats).
@subsubheading Functions
@cppdef si_octets_to_string
@lspdef ext:octets-to-string
@defun ext:octets-to-string octets &key (external-format :default) (start 0) (end nil)
Decode a sequence of octets (i.e. 8-bit bytes) into a string according
to the given external format. @var{octets} must be a vector whose
elements have a size of 8-bit. The bounding index designators
@var{start} and @var{end} optionally denote a subsequence to be decoded.
Signals an @coderef{ext:character-decoding-error} if the decoding fails.
@end defun
@cppdef si_string_to_octets
@lspdef ext:string-to-octets
@defun ext:string-to-octets string &key (external-format :default) (start 0) (end nil) (null-terminate nil)
Encode a string into a sequence of octets according to the given
external format. The bounding index designators @var{start} and
@var{end} optionally denote a subsequence to be encoded. If
@var{null-terminate} is true, add a terminating null byte. Signals an
@coderef{ext:character-encoding-error} if the encoding fails.
@end defun
@subsubsection ANSI dictionary
Common Lisp and C equivalence