Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Aug 28, 2024
1 parent 27650c4 commit 10e7c82
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/dm_uuid.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,14 @@ impure elemental function dm_uuid4_hyphens() result(uuid)
!! seeded before the first invocation by calling `dm_init()` once.
character(len=UUID_FULL_LEN) :: uuid

integer :: i, j, k
integer :: b(UUID_LEN)
real :: r(UUID_LEN)

call random_number(r)

b = int(r * 16)
b(13) = 4
b(17) = ior(iand(b(17), 3), 8)

j = 1

do i = 1, UUID_LEN + 4
select case (i)
case (9, 14, 19, 24)
uuid(i:i) = '-'
case default
k = 1 + b(j)
uuid(i:i) = UUID_SET(k:k)
j = j + 1
end select
end do
uuid = dm_uuid4_hyphenize(dm_uuid4())
end function dm_uuid4_hyphens

pure elemental function dm_uuid4_hyphenize(uuid) result(str)
!! Returns given UUID with hyphens, i.e., turns string
!! `00000000000000000000000000000000` into
!! `00000000-0000-0000-0000-000000000000`.
!! `00000000-0000-0000-0000-000000000000`. The function does not
!! validate the passed indentifier.
character(len=UUID_LEN), intent(in) :: uuid
character(len=UUID_FULL_LEN) :: str

Expand Down

0 comments on commit 10e7c82

Please sign in to comment.