mie: add strict-naming support to mie_name_map

in strict mode, the hint is taken as the required name. if a value already
exists with the given name, the operation fails.
This commit is contained in:
2025-04-22 15:21:30 +01:00
parent f8c322ef6c
commit 4ffe445572
4 changed files with 17 additions and 4 deletions

View File

@@ -123,7 +123,8 @@ static b_status put_name(struct mie_name_map *map, struct mie_name *name)
}
struct mie_name *mie_name_map_put(
struct mie_name_map *map, struct mie_name *entry, const char *hint)
struct mie_name_map *map, struct mie_name *entry, const char *hint,
enum mie_name_map_flags flags)
{
memset(entry, 0x0, sizeof *entry);
entry->n_base.e_type = MIE_NAME_MAP_E_NAME;
@@ -149,6 +150,12 @@ struct mie_name *mie_name_map_put(
}
}
if (flags & MIE_NAME_MAP_STRICT) {
/* the caller insists that `hint` be used as the name.
* such a name already exists, so we can't help them */
return NULL;
}
/* that name already exists, use a suffix to make the name unique.
* alternately, no hint was specified, so it's up to us to generate the name */
b_rope dot = B_ROPE_CHAR('.');