You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce a new Prolog predicate, string_bytes/3 designed for converting string representations into bytes based on a specified encoding.
This predicate lays the groundwork for the development of further conversion predicates, especially those pertinent to base64 and base58 encodings.
Spec proposal
string_bytes/3 is a predicate that unifies a string with a list of bytes, returning true when the (Unicode) String is
represented by Bytes in Encoding. This predicate should be functionally aligned with the SWI-Prolog implementation (except for errors).
The signature is as follows:
string_bytes(?String, ?Bytes, +Encoding)
Where:
String is the string to convert to bytes. It can be an Atom, string or list of characters codes.
Bytes is the list of numbers between 0 and 255 that represent the sequence of bytes.
Encoding is the encoding to use for the conversion.
Encoding can be one of the following:
text considers the string as a sequence of Unicode characters.
octet considers the string as a sequence of bytes.
utf8 considers the string as a sequence of UTF-8 characters.
<encoding> considers the string as a sequence of characters in the given encoding.
At least one of String or Bytes must be instantiated.
Examples:
# Convert a string to a list of bytes.
- string_bytes('Hello World', Bytes, octet).
# Convert a list of bytes to a string.
- string_bytes(String, [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100], octet).
The text was updated successfully, but these errors were encountered:
Idea
Introduce a new Prolog predicate,
string_bytes/3
designed for converting string representations into bytes based on a specified encoding.This predicate lays the groundwork for the development of further conversion predicates, especially those pertinent to
base64
andbase58
encodings.Spec proposal
string_bytes/3
is a predicate that unifies a string with a list of bytes, returning true when the (Unicode)String
isrepresented by
Bytes
inEncoding
. This predicate should be functionally aligned with the SWI-Prolog implementation (except for errors).The signature is as follows:
Where:
String
is the string to convert to bytes. It can be an Atom, string or list of characters codes.Bytes
is the list of numbers between 0 and 255 that represent the sequence of bytes.Encoding
is the encoding to use for the conversion.Encoding can be one of the following:
text
considers the string as a sequence of Unicode characters.octet
considers the string as a sequence of bytes.utf8
considers the string as a sequence of UTF-8 characters.<encoding>
considers the string as a sequence of characters in the given encoding.At least one of
String
orBytes
must be instantiated.Examples:
The text was updated successfully, but these errors were encountered: