Expand description
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());
Structs
- Represents a string in Commodore PETSCII encoding.
Enums
Constants
- Maps PETSCII bytes to Unicode sequences.
Statics
- Maps Unicode sequences to PETSCII bytes.
Functions
- Decodes a variable-sized byte array containing a PETSCII string.
- Decodes a fixed-size byte array containing a PETSCII string.
- Encodes a string in PETSCII.
- Attempts to encode a string in PETSCII.