31 lines
677 B
Plaintext
31 lines
677 B
Plaintext
ns std::core
|
|
|
|
use std::text::Encoding
|
|
|
|
pub int String : Display {
|
|
|
|
bytes: Array<Byte>
|
|
characters: Array<Character>
|
|
encoding: Encoding
|
|
length: Int
|
|
|
|
impl fn to_string() = self
|
|
|
|
}
|
|
|
|
impl Utf8String(bytes: Array<Byte>) : String {
|
|
impl fn get_encoding() = Encoding::Utf8
|
|
impl fn get_length() = bytes.length
|
|
impl fn get_characters() = todo('parse the utf8 bytes and return an Array<Character>')
|
|
}
|
|
|
|
pub mod string {
|
|
|
|
// Example usage:
|
|
// let bytes = array::of(0x64, 0x65, 0x69, 0x6d, 0x6f, 0x73)
|
|
// let s = string::from_utf8_bytes(bytes)
|
|
// println s // "deimos"
|
|
fn from_utf8_bytes(bytes: Array<Byte>): String = Utf8String(bytes)
|
|
|
|
}
|