Add from_str to stdlib

This commit is contained in:
Sofia 2025-07-22 20:07:42 +03:00
parent 28437aecb6
commit 64418635a5
2 changed files with 7 additions and 10 deletions

View File

@ -37,11 +37,13 @@ pub fn new_string() -> String {
pub fn from_str(str: *char) -> String {
let length = str_length(str, 0);
String {
inner: str,
let cloned = malloc(length as u64) as *char;
copy_bits(str, cloned, 0, length as u64);
return String {
inner: cloned,
length: length,
max_length: length
}
};
}
pub fn add_char(string: &mut String, c: char) {

View File

@ -1,15 +1,10 @@
import std::print;
import std::new_string;
import std::from_str;
import std::add_char;
import std::free_string;
fn main() -> i32 {
let mut test = new_string();
add_char(&mut test, 'h');
add_char(&mut test, 'e');
add_char(&mut test, 'l');
add_char(&mut test, 'l');
add_char(&mut test, 'o');
let mut test = from_str("hello world");
print(&test);