MCPcopy Create free account
hub / github.com/dolthub/doltgresql / UnmarshalText

Method UnmarshalText

postgres/parser/uuid/codec.go:114–140  ·  view source on GitHub ↗

UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" "6ba7b8109dad11d180b400c04fd430c8" "{6ba7b8109dad11d180b400c04fd43

(text []byte)

Source from the content-addressed store, hash-verified

112// braced := '{' plain '}' | '{' hashlike '}'
113// urn := URN ':' UUID-NID ':' plain
114func (u *UUID) UnmarshalText(text []byte) error {
115 switch len(text) {
116 case 32:
117 return u.decodeHashLike(text)
118 case 34, 38:
119 return u.decodeBraced(text)
120 case 36:
121 return u.decodeCanonical(text)
122 case 41, 45:
123 return u.decodeURN(text)
124 default:
125 // Postgres allows for an extended dash placement scheme. We'll eventually support those explicitly, but for
126 // now, we'll just "support" them all by removing the dashes so that the UUID is in a dash-less state.
127 shortenedText := bytes.ReplaceAll(text, []byte{'-'}, nil)
128 switch len(shortenedText) {
129 case 32:
130 return u.decodeHashLike(shortenedText)
131 case 34, 38:
132 return u.decodeBraced(shortenedText)
133 case 36:
134 return u.decodeCanonical(shortenedText)
135 case 41, 45:
136 return u.decodeURN(shortenedText)
137 }
138 return fmt.Errorf("uuid: incorrect UUID length: %s", text)
139 }
140}
141
142// decodeCanonical decodes UUID strings that are formatted as defined in RFC-4122 (section 3):
143// "6ba7b810-9dad-11d1-80b4-00c04fd430c8".

Callers 2

ScanMethod · 0.95
FromStringFunction · 0.95

Calls 5

decodeHashLikeMethod · 0.95
decodeBracedMethod · 0.95
decodeCanonicalMethod · 0.95
decodeURNMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected