Skip to content

Commit d4c1ff5

Browse files
author
Лосев Станислав
committed
Fix switch-vase into Validate func
1 parent 0e97ed3 commit d4c1ff5

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

uuid.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ func Validate(s string) error {
224224
switch len(s) {
225225
// Standard UUID format
226226
case 36:
227+
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
228+
return ErrInvalidUUIDFormat
229+
}
230+
for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} {
231+
if _, ok := xtob(s[x], s[x+1]); !ok {
232+
return ErrInvalidUUIDFormat
233+
}
234+
}
227235

228236
// UUID with "urn:uuid:" prefix
229237
case 36 + 9:
@@ -252,18 +260,6 @@ func Validate(s string) error {
252260
return invalidLengthError{len(s)}
253261
}
254262

255-
// Check for standard UUID format
256-
if len(s) == 36 {
257-
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
258-
return ErrInvalidUUIDFormat
259-
}
260-
for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} {
261-
if _, ok := xtob(s[x], s[x+1]); !ok {
262-
return ErrInvalidUUIDFormat
263-
}
264-
}
265-
}
266-
267263
return nil
268264
}
269265

0 commit comments

Comments
 (0)