Hex implements formatStringInterpolator.Hex.
(useUpper bool)
| 365 | |
| 366 | // Hex implements formatStringInterpolator.Hex. |
| 367 | func (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. |
| 398 | func (c *stringFormatter) Octal(arg ref.Val, locale string) (string, error) { |
nothing calls this directly
no test coverage detected