hare

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

ident.ha (837B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use strings;
      5 
      6 // Identifies a single object, e.g. foo::bar::baz.
      7 export type ident = []str;
      8 
      9 // Maximum length of an identifier, as the sum of the lengths of its parts plus
     10 // one for each namespace deliniation.
     11 //
     12 // In other words, the length of "a::b::c" is 5.
     13 export def IDENT_MAX: size = 255;
     14 
     15 // Frees resources associated with an [[ident]]ifier.
     16 export fn ident_free(ident: ident) void = strings::freeall(ident);
     17 
     18 // Returns true if two [[ident]]s are identical.
     19 export fn ident_eq(a: ident, b: ident) bool = {
     20 	if (len(a) != len(b)) {
     21 		return false;
     22 	};
     23 	for (let i = 0z; i < len(a); i += 1) {
     24 		if (a[i] != b[i]) {
     25 			return false;
     26 		};
     27 	};
     28 	return true;
     29 };
     30 
     31 // Duplicates an [[ident]].
     32 export fn ident_dup(id: ident) ident = strings::dupall(id);