Hex implements formatStringInterpolatorV2.Hex.
(useUpper bool)
| 342 | |
| 343 | // Hex implements formatStringInterpolatorV2.Hex. |
| 344 | func (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. |
| 384 | func (c *stringFormatterV2) Octal(arg ref.Val) (string, error) { |
nothing calls this directly
no test coverage detected