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

Method Hex

ext/formatting_v2.go:344–381  ·  view source on GitHub ↗

Hex implements formatStringInterpolatorV2.Hex.

(useUpper bool)

Source from the content-addressed store, hash-verified

342
343// Hex implements formatStringInterpolatorV2.Hex.
344func (c *stringFormatterV2) Hex(useUpper bool) func(ref.Val) (string, error) {
345 return func(arg ref.Val) (string, error) {
346 var fmtStr string
347 if useUpper {
348 fmtStr = "%X"
349 } else {
350 fmtStr = "%x"
351 }
352 switch arg.Type() {
353 case types.IntType:
354 argInt, ok := arg.Value().(int64)
355 if !ok {
356 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.IntType)
357 }
358 return fmt.Sprintf(fmtStr, argInt), nil
359 case types.UintType:
360 argUint, ok := arg.Value().(uint64)
361 if !ok {
362 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.UintType)
363 }
364 return fmt.Sprintf(fmtStr, argUint), nil
365 case types.StringType:
366 argStr, ok := arg.Value().(string)
367 if !ok {
368 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.StringType)
369 }
370 return fmt.Sprintf(fmtStr, argStr), nil
371 case types.BytesType:
372 argBytes, ok := arg.Value().([]byte)
373 if !ok {
374 return "", fmt.Errorf("type conversion error from '%s' to '%s'", arg.Type(), types.BytesType)
375 }
376 return fmt.Sprintf(fmtStr, argBytes), nil
377 default:
378 return "", hexFormatErrorV2(runtimeID, arg.Type().TypeName())
379 }
380 }
381}
382
383// Octal implements formatStringInterpolatorV2.Octal.
384func (c *stringFormatterV2) Octal(arg ref.Val) (string, error) {

Callers

nothing calls this directly

Calls 4

hexFormatErrorV2Function · 0.85
TypeMethod · 0.65
ValueMethod · 0.65
TypeNameMethod · 0.65

Tested by

no test coverage detected