Make breaking changes to stdlib
This commit is contained in:
parent
de803e9024
commit
aeca557b6f
@ -9,18 +9,17 @@ import std::concat_strings;
|
|||||||
|
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let mut test = from_str("hello");
|
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, '!');
|
||||||
add_char(&mut test, '\n');
|
add_char(&mut test, '\n');
|
||||||
|
|
||||||
add_num_to_str(&mut test, 175);
|
add_num_to_str(&mut test, 175);
|
||||||
|
|
||||||
print(&test);
|
print(test);
|
||||||
|
|
||||||
free_string(&mut test);
|
free_string(&test);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ struct div_t {
|
|||||||
remainder: i32,
|
remainder: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(message: &String) {
|
pub fn print(message: String) {
|
||||||
puts(*message.inner);
|
puts(message.inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_div(numerator: i32, denominator: i32) -> div_t {
|
pub fn int_div(numerator: i32, denominator: i32) -> div_t {
|
||||||
@ -46,7 +46,7 @@ pub fn from_str(str: *char) -> String {
|
|||||||
max_length: length,
|
max_length: length,
|
||||||
must_be_freed: false,
|
must_be_freed: false,
|
||||||
};
|
};
|
||||||
concat_strings(&mut new, &static);
|
concat_strings(&mut new, static);
|
||||||
return new;
|
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);
|
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'); }
|
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 {
|
pub fn clamp(min: f32, max: f32, value: f32) -> f32 {
|
||||||
if value > max {
|
if value > max {
|
||||||
return max;
|
return max;
|
||||||
@ -126,9 +132,3 @@ pub fn abs(f: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
return f;
|
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user