File: cstrings.ha

package info (click to toggle)
harec 0.24.2-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,412 kB
  • sloc: ansic: 20,221; asm: 247; makefile: 118; lisp: 80; sh: 45
file content (19 lines) | stat: -rw-r--r-- 376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type string = struct {
	data: nullable *[*]u8,
	length: size,
	capacity: size,
};

export fn toutf8(s: str) []u8 = *(&s: *[]u8);

fn constchar(s: str) *const u8 = {
	let s = &s: *string;
	return s.data: *const u8;
};

fn alloc_constchar(s: str) *const u8 = {
	let c: []u8 = alloc([], len(s) + 1);
	append(c, *(&s: *[]u8)...);
	append(c, 0);
	return constchar(*(&c: *str));
};