ident.ha (595B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use encoding::utf8; 5 use strings; 6 7 // Converts a symbol name to a Hare identifier. The return value is statically 8 // allocated. 9 export fn symname_to_ident(name: str) const str = { 10 static let buf: [MAX_SYMNAME * 2]u8 = [0...]; 11 let slice = buf[..0]; 12 13 const iter = strings::iter(name); 14 for (const rn => strings::next(&iter)) { 15 if (rn == '.') { 16 static append(slice, ':'); 17 static append(slice, ':'); 18 } else { 19 static append(slice, utf8::encoderune(rn)...); 20 }; 21 }; 22 23 return strings::fromutf8(slice)!; 24 };