Name constructs a new name constant while checking that constant symbol starts with a '/' and does not contain empty parts.
(symbol string)
| 282 | // Name constructs a new name constant while checking that constant symbol starts with a '/' and |
| 283 | // does not contain empty parts. |
| 284 | func 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. |
| 303 | func String(str string) Constant { |