Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧠 Logic: 🧵 string_bytes/3 predicate #497

Closed
ccamel opened this issue Jan 7, 2024 · 0 comments
Closed

🧠 Logic: 🧵 string_bytes/3 predicate #497

ccamel opened this issue Jan 7, 2024 · 0 comments
Assignees

Comments

@ccamel
Copy link
Member

ccamel commented Jan 7, 2024

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 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).
@ccamel ccamel self-assigned this Jan 7, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in 💻 Development Jan 7, 2024
@ccamel ccamel moved this from 📋 Backlog to 🏗 In progress in 💻 Development Jan 7, 2024
@ccamel ccamel moved this from 🏗 In progress to ✅ Done in 💻 Development Feb 14, 2024
@ccamel ccamel closed this as completed Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant