Packages
jsv
0.11.3
0.21.2
0.21.1
0.21.0
0.20.0
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.3
0.18.2
0.18.1
0.18.0
0.17.1
0.17.0
0.16.0
0.15.2
0.15.1
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.5
0.11.4
0.11.3
retired
0.11.2
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.0
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
A JSON Schema Validator with complete support for the latest specifications.
Retired package: Release invalid - invalid error handling
Current section
Files
Jump to
Current section
Files
lib/jsv/format_validator/default/optional/uuid.ex
# credo:disable-for-this-file Credo.Check.Refactor.CyclomaticComplexity
defmodule JSV.FormatValidator.Default.Optional.UUID do
@moduledoc false
defguard is_hex(n) when n in ?0..?9 or n in ?a..?f or n in ?A..?F
@doc false
@spec parse_uuid(binary) :: {:ok, binary} | {:error, :invalid_uuid_format}
def parse_uuid(
<<a1, a2, a3, a4, a5, a6, a7, a8, ?-, b1, b2, b3, b4, ?-, c1, c2, c3, c4, ?-, d1, d2, d3, d4, ?-, e1, e2, e3,
e4, e5, e6, e7, e8, e9, e10, e11, e12>> = data
)
when is_hex(a1) and
is_hex(a2) and
is_hex(a3) and
is_hex(a4) and
is_hex(a5) and
is_hex(a6) and
is_hex(a7) and
is_hex(a8) and
is_hex(b1) and
is_hex(b2) and
is_hex(b3) and
is_hex(b4) and
is_hex(c1) and
is_hex(c2) and
is_hex(c3) and
is_hex(c4) and
is_hex(d1) and
is_hex(d2) and
is_hex(d3) and
is_hex(d4) and
is_hex(e1) and
is_hex(e2) and
is_hex(e3) and
is_hex(e4) and
is_hex(e5) and
is_hex(e6) and
is_hex(e7) and
is_hex(e8) and
is_hex(e9) and
is_hex(e10) and
is_hex(e11) and
is_hex(e12) do
{:ok, data}
end
#
def parse_uuid(_) do
{:error, :invalid_uuid_format}
end
end