Add from_str to stdlib
This commit is contained in:
		
							parent
							
								
									28437aecb6
								
							
						
					
					
						commit
						64418635a5
					
				| @ -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) { | ||||
|  | ||||
| @ -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); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user