27 lines
510 B
Plaintext
27 lines
510 B
Plaintext
ns std::core
|
|
|
|
pub int String {
|
|
bytes: byte[]
|
|
encoding: Encoding
|
|
length: Int
|
|
}
|
|
|
|
pub enum Encoding {
|
|
Utf8, Utf16, Ascii
|
|
}
|
|
|
|
pub impl Utf8String(bytes: byte[]) : String {
|
|
impl fn get_encoding() = Encoding::Utf8
|
|
impl fn get_length() = bytes.length
|
|
}
|
|
|
|
pub mod string {
|
|
|
|
// Example usage:
|
|
// let bytes = [0x64, 0x65, 0x69, 0x6d, 0x6f, 0x73]
|
|
// let s = string::from_utf8_bytes(bytes)
|
|
// println s // "deimos"
|
|
fn from_utf8_bytes(bytes: byte[]): String = Utf8String(bytes)
|
|
|
|
}
|