Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptazhou committed Mar 30, 2024
1 parent 501ceb5 commit de9a58a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ jobs:
ignore-no-cache: true
- uses: julia-actions/julia-runtest@v1
- uses: heptazhou/julia-codecov@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v3.1.5
with:
file: lcov.info
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ authors = ["Heptazhou <zhou at 0h7z dot com>"]
version = "1.10.0"

[deps]
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[weakdeps]
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"

[extras]
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["OrderedCollections", "Test"]
32 changes: 10 additions & 22 deletions src/UUID4.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022-2023 Heptazhou <[email protected]>
# Copyright (C) 2022-2024 Heptazhou <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -28,10 +28,8 @@ export uuid_string
export uuid_version

export AbstractRNG, MersenneTwister, RandomDevice
export LittleDict, OrderedDict
export UUID
using Base: UUID
using OrderedCollections: LittleDict, OrderedDict
using Random: AbstractRNG, MersenneTwister, RandomDevice

"""
Expand Down Expand Up @@ -156,25 +154,15 @@ function uuid_string(fmt::Int, id::UUID = uuid())::String
uuid_string(id, fmt)
end
function uuid_string(id::UUID, fmt::Int)::String
if 0 fmt
argumenterror("Invalid format `$fmt` (should be positive)")
elseif fmt 36
string(id)
elseif fmt 22
string(id.value, base = 62, pad = fmt)
elseif fmt 25
string(id.value, base = 36, pad = fmt)
elseif fmt 32
string(id.value, base = 16, pad = fmt)
elseif fmt 24
replace(uuid_string(id, 22), r"(.{7})" => s"\1-", count = fmt - 22)
elseif fmt 29
replace(uuid_string(id, 25), r"(.{5})" => s"\1-", count = fmt - 25)
elseif fmt 39
replace(uuid_string(id, 32), r"(.{4})" => s"\1-", count = fmt - 32)
else
argumenterror("Invalid format `$fmt` (undefined)")
end
fmt <= 00 ? argumenterror("Invalid format `$fmt` (should be positive)") :
fmt == 36 ? string(id) :
fmt == 22 ? string(id.value, base = 62, pad = fmt) :
fmt == 25 ? string(id.value, base = 36, pad = fmt) :
fmt == 32 ? string(id.value, base = 16, pad = fmt) :
fmt == 24 ? replace(uuid_string(id, 22), r"(.{7})" => s"\1-", count = fmt - 22) :
fmt == 29 ? replace(uuid_string(id, 25), r"(.{5})" => s"\1-", count = fmt - 25) :
fmt == 39 ? replace(uuid_string(id, 32), r"(.{4})" => s"\1-", count = fmt - 32) :
argumenterror("Invalid format `$fmt` (not defined)")
end

"""
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022-2023 Heptazhou <[email protected]>
# Copyright (C) 2022-2024 Heptazhou <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

using OrderedCollections: LittleDict, OrderedDict
using Random: Random
using Test, UUID4

Expand Down

0 comments on commit de9a58a

Please sign in to comment.