blob: 4393efa23be31a618c8e3d71291c216fa40b3b51 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package fidlgen
type NameChanger func(string) string
type NameContext struct {
reserved map[string]struct{}
changer NameChanger
}
func NewNameContext(changer NameChanger) NameContext {
return NameContext{
reserved: make(map[string]struct{}),
changer: changer,
}
}
func ReserveNames(names map[string][]NameContext) {
for name, contexts := range names {
for _, context := range contexts {
context.reserved[name] = struct{}{}
}
}
}
func (c *NameContext) IsReserved(name string) bool {
_, ok := c.reserved[name]
return ok
}
func (c *NameContext) ChangeIfReserved(name string) string {
if c.IsReserved(name) {
return c.changer(name)
}
return name
}