harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

cstrings.ha (386B)


      1 type string = struct {
      2 	data: nullable *[*]u8,
      3 	length: size,
      4 	capacity: size,
      5 };
      6 
      7 export fn toutf8(s: str) []u8 = *(&s: *[]u8);
      8 
      9 fn constchar(s: str) *const char = {
     10 	let s = &s: *string;
     11 	return s.data: *const char;
     12 };
     13 
     14 fn alloc_constchar(s: str) *const char = {
     15 	let c: []char = alloc([], len(s) + 1);
     16 	append(c, *(&s: *[]char)...);
     17 	append(c, 0);
     18 	return constchar(*(&c: *str));
     19 };