Skip to content

Commit

Permalink
Fix switch-vase into Validate func
Browse files Browse the repository at this point in the history
  • Loading branch information
error0x001 authored and Лосев Станислав committed Oct 14, 2024
1 parent 0e97ed3 commit caf1f68
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ func Validate(s string) error {
switch len(s) {
// Standard UUID format
case 36:
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
return ErrInvalidUUIDFormat
}
for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} {
if _, ok := xtob(s[x], s[x+1]); !ok {
return ErrInvalidUUIDFormat
}
}

// UUID with "urn:uuid:" prefix
case 36 + 9:
Expand Down Expand Up @@ -252,18 +260,6 @@ func Validate(s string) error {
return invalidLengthError{len(s)}
}

// Check for standard UUID format
if len(s) == 36 {
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
return ErrInvalidUUIDFormat
}
for _, x := range []int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} {
if _, ok := xtob(s[x], s[x+1]); !ok {
return ErrInvalidUUIDFormat
}
}
}

return nil
}

Expand Down

0 comments on commit caf1f68

Please sign in to comment.