mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 19:16:35 +00:00
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
|
|
|
|
fn print(msg: string) #[builtin(Print)] {}
|
|
fn println(msg: string) { print(msg + "\n") }
|
|
|
|
fn string_push_char(str: string, value: int) -> string #[builtin(StringPushChar)] {}
|
|
fn string_char_at(str: string, index: int) -> int #[builtin(StringCharAt)] {}
|
|
fn string_length(str: string) -> int #[builtin(StringLength)] {}
|
|
|
|
fn array_new_string() -> [string] #[builtin(ArrayNew)] {}
|
|
fn array_push_string(array: [string], value: string) #[builtin(ArrayPush)] {}
|
|
fn array_length_string(array: [string]) -> int #[builtin(ArrayLength)] {}
|
|
fn array_at_string(array: [string], index: int) -> string #[builtin(ArrayAt)] {}
|
|
|
|
fn char(ch: string) -> int {
|
|
string_char_at(ch, 0)
|
|
}
|
|
|
|
fn split(str: string, seperator: int) -> [string] {
|
|
let result: [string] = array_new_string();
|
|
|
|
let i = 0;
|
|
let current_str = "";
|
|
let str_length = string_length(str);
|
|
loop {
|
|
if i >= str_length {
|
|
break;
|
|
}
|
|
let char = string_char_at(str, i);
|
|
if char == seperator {
|
|
array_push_string(result, current_str);
|
|
current_str = "";
|
|
} else {
|
|
current_str = string_push_char(current_str, char);
|
|
}
|
|
i = i + 1;
|
|
}
|
|
result
|
|
}
|
|
|
|
fn main() {
|
|
let array = split("yaoisfjasoifjsaiofjsa", char("a"));
|
|
let i = 0;
|
|
let array_length = array_length_string(array);
|
|
loop {
|
|
if i >= array_length {
|
|
break;
|
|
}
|
|
println(array_at_string(array, i));
|
|
i = i + 1;
|
|
}
|
|
}
|