hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

cstring.ha (406B)


      1 // License: MPL-2.0
      2 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      3 
      4 fn c_strlen(cstr: *const char) size = {
      5 	const ptr = cstr: *[*]u8;
      6 	let ln = 0z;
      7 	for (ptr[ln] != 0; ln += 1) void;
      8 	return ln;
      9 };
     10 
     11 fn from_c_unsafe(cstr: *const char) const str = {
     12 	const l = c_strlen(cstr);
     13 	const s = struct {
     14 		data: *[*]u8   = cstr: *[*]u8,
     15 		length: size   = l,
     16 		capacity: size = l + 1,
     17 	};
     18 	return *(&s: *const str);
     19 };