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 6bbca62 commit 501ceb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ jobs:
- os: macos-latest
julia-version: nightly
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: julia-actions/setup-julia@v1
with:
show-versioninfo: true
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@v1
with:
ignore-no-cache: true
- uses: julia-actions/julia-runtest@v1
- uses: heptazhou/julia-codecov@v1
- uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UUID4"
uuid = "379725f3-1ad5-416d-b88a-50ced391fe04"
authors = ["Heptazhou <zhou at 0h7z dot com>"]
version = "1.8.0"
version = "1.10.0"

[deps]
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Expand Down
32 changes: 14 additions & 18 deletions src/UUID4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
UUID4
The `UUID4` module provides universally unique identifier (UUID), version 4,
This module provides universally unique identifier (UUID) version 4,
along with related functions.
"""
module UUID4
Expand All @@ -30,15 +30,15 @@ export uuid_version
export AbstractRNG, MersenneTwister, RandomDevice
export LittleDict, OrderedDict
export UUID
const UUID = Base.UUID
using Base: UUID
using OrderedCollections: LittleDict, OrderedDict
using Random: AbstractRNG, MersenneTwister, RandomDevice

"""
uuid(rng::AbstractRNG = RandomDevice()) -> UUID
Generate a version 4 (random or pseudo-random) universally unique identifier
(UUID), as specified by [RFC 4122](https://www.ietf.org/rfc/rfc4122).
Generate a version 4 (random or pseudo-random) universally unique identifier (UUID),
as specified by [RFC 4122](https://tools.ietf.org/html/rfc4122).
# Examples
```jldoctest
Expand Down Expand Up @@ -76,16 +76,13 @@ function uuid_formats()::Vector{Int}
end

"""
uuid_parse(str::String; fmt::Int = length(str)) -> Tuple{Int, UUID}
uuid_parse(str::AbstractString; fmt::Int = length(str)) -> Tuple{Int, UUID}
"""
function uuid_parse end
function uuid_parse(str::UUID; fmt::Any = 0x0)::Tuple{Int, UUID}
uuid_parse(string(str); fmt = Int(fmt))
function uuid_parse(id::UUID; fmt::Number = 0)::Tuple{Int, UUID}
(length("$id"), id) # 36, id
end
function uuid_parse(str::Any; fmt::Number = 0)::Tuple{Int, UUID}
uuid_parse(String(str); fmt = Int(fmt))
end
function uuid_parse(str::String; fmt::Int = 0)::Tuple{Int, UUID}
function uuid_parse(str::AbstractString; fmt::Int = 0)::Tuple{Int, UUID}
len = length(str)
ret = if 0 > fmt
argumenterror("Invalid format `$fmt` (should be positive)")
Expand Down Expand Up @@ -181,11 +178,11 @@ function uuid_string(id::UUID, fmt::Int)::String
end

"""
uuid_version(id::String) -> Int
uuid_version(id::UUID) -> Int
uuid_version(id::AbstractString) -> Int
uuid_version(id::UUID) -> Int
Inspect the given UUID or UUID string and return its version (see [RFC
4122](https://www.ietf.org/rfc/rfc4122)).
Inspect the given UUID or UUID string and return its version
(see [RFC 4122](https://tools.ietf.org/html/rfc4122)).
# Examples
```jldoctest
Expand All @@ -194,9 +191,8 @@ julia> uuid_version(uuid())
```
"""
function uuid_version end
uuid_version(id::Any)::Int = uuid_version(String(id))
uuid_version(id::String)::Int = uuid_version(uuid_parse(id)[end])
uuid_version(id::UUID)::Int = Int(id.value >> 76 & 0xf)
uuid_version(id::Any)::Int = uuid_version(uuid_parse(id)[end])
uuid_version(id::UUID)::Int = id.value >> 76 & 0xf |> Int

@noinline argumenterror(msg::AbstractString) = throw(ArgumentError(msg))

Expand Down

0 comments on commit 501ceb5

Please sign in to comment.