MCPcopy
hub / github.com/gofrs/uuid / Format

Method Format

uuid.go:266–295  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
266func (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
297func toUpperHex(b []byte) {
298 for i, c := range b {

Callers

nothing calls this directly

Calls 4

MarshalTextMethod · 0.95
StringMethod · 0.95
toUpperHexFunction · 0.85
encodeCanonicalFunction · 0.85

Tested by

no test coverage detected