-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
18 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
||
""" | ||
|
@@ -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 | ||
|
||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
||
|