aboutsummaryrefslogtreecommitdiff
path: root/core/strings.odin
blob: f8697e46eb6773884b85c57254bd174e0f336581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import "core:mem.odin"

new_string :: proc(s: string) -> string {
	c := make([]u8, len(s)+1);
	copy(c, cast([]u8)s);
	c[len(s)] = 0;
	return string(c[..len(s)]);
}

new_c_string :: proc(s: string) -> ^u8 {
	c := make([]u8, len(s)+1);
	copy(c, cast([]u8)s);
	c[len(s)] = 0;
	return &c[0];
}

to_odin_string :: proc(str: ^u8) -> string {
	if str == nil do return "";
	end := str;
	for end^ != 0 do end+=1;
	return string(mem.slice_ptr(str, end-str));
}