Format implements fmt.Formatter for UUID values. The behavior is as follows: The 'x' and 'X' verbs output only the hex digits of the UUID, using a-f for 'x' and A-F for 'X'. The 'v', '+v', 's' and 'q' verbs return the canonical RFC-9562 string representation. The 'S' verb returns the RFC-9562 forma
(f fmt.State, c rune)
| 264 | // All other verbs not handled directly by the fmt package (like '%p') are unsupported and will return |
| 265 | // "%!verb(uuid.UUID=value)" as recommended by the fmt package. |
| 266 | func (u UUID) Format(f fmt.State, c rune) { |
| 267 | if c == 'v' && f.Flag('#') { |
| 268 | fmt.Fprintf(f, "%#v", [Size]byte(u)) |
| 269 | return |
| 270 | } |
| 271 | switch c { |
| 272 | case 'x', 'X': |
| 273 | b := make([]byte, 32) |
| 274 | hex.Encode(b, u[:]) |
| 275 | if c == 'X' { |
| 276 | toUpperHex(b) |
| 277 | } |
| 278 | _, _ = f.Write(b) |
| 279 | case 'v', 's', 'S': |
| 280 | b, _ := u.MarshalText() |
| 281 | if c == 'S' { |
| 282 | toUpperHex(b) |
| 283 | } |
| 284 | _, _ = f.Write(b) |
| 285 | case 'q': |
| 286 | b := make([]byte, 38) |
| 287 | b[0] = '"' |
| 288 | encodeCanonical(b[1:], u) |
| 289 | b[37] = '"' |
| 290 | _, _ = f.Write(b) |
| 291 | default: |
| 292 | // invalid/unsupported format verb |
| 293 | fmt.Fprintf(f, "%%!%c(uuid.UUID=%s)", c, u.String()) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | func toUpperHex(b []byte) { |
| 298 | for i, c := range b { |
nothing calls this directly
no test coverage detected