Binary implements formatStringInterpolator.Binary.
(arg ref.Val, locale string)
| 343 | |
| 344 | // Binary implements formatStringInterpolator.Binary. |
| 345 | func (c *stringFormatter) Binary(arg ref.Val, locale string) (string, error) { |
| 346 | switch arg.Type() { |
| 347 | case types.IntType: |
| 348 | argInt := arg.Value().(int64) |
| 349 | // locale is intentionally unused as integers formatted as binary |
| 350 | // strings are locale-independent |
| 351 | return fmt.Sprintf("%b", argInt), nil |
| 352 | case types.UintType: |
| 353 | argInt := arg.Value().(uint64) |
| 354 | return fmt.Sprintf("%b", argInt), nil |
| 355 | case types.BoolType: |
| 356 | argBool := arg.Value().(bool) |
| 357 | if argBool { |
| 358 | return "1", nil |
| 359 | } |
| 360 | return "0", nil |
| 361 | default: |
| 362 | return "", binaryFormatError(runtimeID, arg.Type().TypeName()) |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Hex implements formatStringInterpolator.Hex. |
| 367 | func (c *stringFormatter) Hex(useUpper bool) func(ref.Val, string) (string, error) { |
nothing calls this directly
no test coverage detected