Add string library file.
This commit is contained in:
parent
5732c4d197
commit
b90111dfd5
26
dm_lib/std/core/string.dm
Normal file
26
dm_lib/std/core/string.dm
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user