MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Hex

Method Hex

ext/formatting.go:367–395  ·  view source on GitHub ↗

Hex implements formatStringInterpolator.Hex.

(useUpper bool)

Source from the content-addressed store, hash-verified

365
366// Hex implements formatStringInterpolator.Hex.
367func (c *stringFormatter) Hex(useUpper bool) func(ref.Val, string) (string, error) {
368 return func(arg ref.Val, locale string) (string, error) {
369 fmtStr := "%x"
370 if useUpper {
371 fmtStr = "%X"
372 }
373 switch arg.Type() {
374 case types.StringType, types.BytesType:
375 if arg.Type() == types.BytesType {
376 return fmt.Sprintf(fmtStr, arg.Value().([]byte)), nil
377 }
378 return fmt.Sprintf(fmtStr, arg.Value().(string)), nil
379 case types.IntType:
380 argInt, ok := arg.Value().(int64)
381 if !ok {
382 return "", fmt.Errorf("could not convert \"%s\" to int64", arg.Value())
383 }
384 return fmt.Sprintf(fmtStr, argInt), nil
385 case types.UintType:
386 argInt, ok := arg.Value().(uint64)
387 if !ok {
388 return "", fmt.Errorf("could not convert \"%s\" to uint64", arg.Value())
389 }
390 return fmt.Sprintf(fmtStr, argInt), nil
391 default:
392 return "", hexFormatError(runtimeID, arg.Type().TypeName())
393 }
394 }
395}
396
397// Octal implements formatStringInterpolator.Octal.
398func (c *stringFormatter) Octal(arg ref.Val, locale string) (string, error) {

Callers

nothing calls this directly

Calls 4

hexFormatErrorFunction · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected