MCPcopy
hub / github.com/google/mangle / Name

Function Name

ast/ast.go:284–300  ·  view source on GitHub ↗

Name constructs a new name constant while checking that constant symbol starts with a '/' and does not contain empty parts.

(symbol string)

Source from the content-addressed store, hash-verified

282// Name constructs a new name constant while checking that constant symbol starts with a '/' and
283// does not contain empty parts.
284func Name(symbol string) (Constant, error) {
285 switch {
286 case len(symbol) <= 1:
287 return Constant{}, fmt.Errorf("constant symbol must be a non-empty string starting with '/'")
288 case symbol[0] != '/':
289 return Constant{}, fmt.Errorf("constant symbol must start with '/'")
290 }
291 if strings.Contains(symbol, "\"") {
292 return Constant{}, fmt.Errorf("this constructor does not handle string content \"%s\"", symbol)
293 }
294 for _, part := range strings.Split(symbol[1:], "/") {
295 if part == "" {
296 return Constant{}, fmt.Errorf("constant symbol \"%s\" contains empty part", symbol)
297 }
298 }
299 return Constant{NameType, symbol, int64(hashBytes([]byte(symbol))), nil, nil}, nil
300}
301
302// String constructs a string constant.
303func String(str string) Constant {

Callers 15

mustNameFunction · 0.92
nameFunction · 0.92
BenchmarkJoinFunction · 0.92
nameFunction · 0.92
nameFunction · 0.92
VisitConstMethod · 0.92
nameFunction · 0.92
nameFunction · 0.92

Calls 2

hashBytesFunction · 0.85
ContainsMethod · 0.65

Tested by 15

mustNameFunction · 0.74
nameFunction · 0.74
BenchmarkJoinFunction · 0.74
nameFunction · 0.74
nameFunction · 0.74
nameFunction · 0.74
nameFunction · 0.74
TestDesugarPropagateFunction · 0.74