petscii

Crates.iopetscii
lib.rspetscii
version0.2.1
sourcesrc
created_at2023-10-13 07:55:02.657329
updated_at2023-10-13 09:16:41.74819
descriptionString library for Commodore PETSCII.
homepage
repositoryhttps://github.com/jkorinth/petscii
max_upload_size
id1002063
size54,071
(jkorinth)

documentation

README

petscii

Support library for Commodore PETSCII strings.

Examples

Produce Unicode strings from raw data

let data = [b'A', b'B', b'C'];
let petscii = petscii::PetsciiString::from(&data);
assert_eq!("ABC", petscii.to_string());

Produce C64 binary correct sequences from strings

let petscii = petscii::PetsciiString::try_from("ANSWER IS 42").unwrap();

// truncate case:
let data_trunc: petscii::Result<[u8; 7]> = petscii.clone().try_into();
assert!(data_trunc.is_err());

// extended buffer case (beware of Commodore's NO_BREAK_SPACE filling):
let data_ext: [u8; 16] = petscii.clone().try_into().unwrap();
assert_eq!(
    format!("{}", petscii::PetsciiString::from(&data_ext)),
    "ANSWER IS 42\u{a0}\u{a0}\u{a0}\u{a0}"
);

Beware that the From<[u8]> implementation silently drops non-printables. If that is not what you want, use TryFrom:

let petscii = petscii::encode("Answer is 42");
assert_eq!(*petscii, [b'A', b' ', b' ', b'4', b'2']);
let fpetscii = petscii::try_encode("Answer is 42");
assert!(fpetscii.is_err());
Commit count: 0

cargo fmt