Make breaking changes to stdlib

This commit is contained in:
Sofia 2025-07-23 22:04:34 +03:00
parent de803e9024
commit aeca557b6f
2 changed files with 13 additions and 14 deletions

View File

@ -9,18 +9,17 @@ import std::concat_strings;
fn main() -> i32 {
let mut test = from_str("hello");
let mut other = from_str(" world");
concat_strings(&mut test, &other);
concat_strings(&mut test, from_str(" world"));
add_char(&mut test, '!');
add_char(&mut test, '\n');
add_num_to_str(&mut test, 175);
print(&test);
print(test);
free_string(&mut test);
free_string(&test);
return 0;
}

View File

@ -9,8 +9,8 @@ struct div_t {
remainder: i32,
}
pub fn print(message: &String) {
puts(*message.inner);
pub fn print(message: String) {
puts(message.inner);
}
pub fn int_div(numerator: i32, denominator: i32) -> div_t {
@ -46,7 +46,7 @@ pub fn from_str(str: *char) -> String {
max_length: length,
must_be_freed: false,
};
concat_strings(&mut new, &static);
concat_strings(&mut new, static);
return new;
}
@ -74,7 +74,7 @@ pub fn set_char(string: &mut String, c: char, position: u64) {
}
}
pub fn free_string(string: &mut String) {
pub fn free_string(string: &String) {
free((*string).inner as *u8);
}
@ -110,6 +110,12 @@ pub fn add_num_to_str(string: &mut String, num: u64) {
else if rem == 9 { add_char(string, '9'); }
}
pub fn concat_strings(destination: &mut String, source: String) {
for i in 0 .. (str_length(source.inner) - 1) {
add_char(destination, source.inner[i]);
}
}
pub fn clamp(min: f32, max: f32, value: f32) -> f32 {
if value > max {
return max;
@ -126,9 +132,3 @@ pub fn abs(f: f32) -> f32 {
}
return f;
}
pub fn concat_strings(destination: &mut String, source: &String) {
for i in 0 .. (str_length((*source).inner) - 1) {
add_char(destination, (*source).inner[i]);
}
}