Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
Browse files Browse the repository at this point in the history
Heptazhou committed Mar 30, 2024

Verified

This commit was signed with the committer’s verified signature.
Heptazhou Heptazhou
1 parent 6bbca62 commit 32d0ec8
Showing 3 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ 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
@@ -42,6 +42,6 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: heptazhou/julia-codecov@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info
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"
32 changes: 14 additions & 18 deletions src/UUID4.jl
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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)")
@@ -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
@@ -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))

0 comments on commit 32d0ec8

Please sign in to comment.