~sircmpwn/hare

hare/rt/+test/cstring.ha -rw-r--r-- 340 bytes
0db89b74Alexey Yerin shlex: correctly handle leading whitespace 5 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fn c_strlen(cstr: *const char) size = {
	const ptr = cstr: *[*]u8;
	let ln = 0z;
	for (ptr[ln] != 0; ln += 1) void;
	return ln;
};

fn from_c_unsafe(cstr: *const char) const str = {
	const l = c_strlen(cstr);
	const s = struct {
		data: *[*]u8   = cstr: *[*]u8,
		length: size   = l,
		capacity: size = l,
	};
	return *(&s: *const str);
};