include "std/vec.moc" struct String { Vec: chars impl: inline fn String.from_vec(Vec) -> [String] { cast(String) } fn String.new(Str: s) -> [String] { s::size Vec.with_capacity:: as [mut chars] 0 while dup s::size < do { as [i] s::data i ptr+ @ *chars Vec.push i 1 + } drop chars cast(String) } inline fn String.null_terminate(Str: s) -> [String] { s String.new '\0' String.push } inline fn String.clone(&String: self) -> [String] { self String.as_str String.new } inline fn String.delete(&String: self) { self::chars Vec.delete } inline fn String.size(&String: self) -> [u64] { self::chars Vec.len } fn String.as_str(&String: self) -> [Str] { self String.size self::chars Vec.slice as [slice] slice::data cast(Str) } inline fn String.push(String: mut self char: c) -> [String] { c *self::chars Vec.push self } fn String.push_str(String: mut self Str: s) -> [String] { 0 while dup s::size < do { as [i] s::data i ptr+ @ *self::chars Vec.push i 1 + } drop self } fn String.format(String: mut self String: other) -> [String] { self 0 while dup &other String.size < do { as [i] i &other::chars Vec.at Option.unwrap String.push i 1 + } drop &other String.delete } inline fn String.at(u64: idx &String: self) -> [Option] { idx self::chars Vec.at } fn String.replace(char: replace char: by String: mut self) -> [String] { 0 while dup &self String.size < do { as [i] i *self::chars Vec.get_mut Option.unwrap as [mut to] to @ replace == if { by to ! } i 1 + } drop self } } impl ToString { inline fn to_string(String) -> [String] {} } impl ToString<&String> { inline fn to_string(&String) -> [String] { String.clone } } impl Write { inline fn write(String: s u64: fd) { &s String.as_str fd write &s String.delete } }