add specs and exported types where needed
This patch exports types that are needed and adds specs where they did not previously exist. It also cleans up and expands the specs where they needed to be cleaned up.
This commit is contained in:
parent
2508e1ed82
commit
07a54bb518
3 changed files with 63 additions and 20 deletions
|
@ -11,6 +11,20 @@
|
|||
compare/2
|
||||
]).
|
||||
|
||||
-export_type([
|
||||
semvar/0
|
||||
]).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Public Types
|
||||
%%%===================================================================
|
||||
|
||||
-type semvar() :: string().
|
||||
-type parsed_semvar() :: {MajorVsn::string(),
|
||||
MinorVsn::string(),
|
||||
PatchVsn::string(),
|
||||
PathString::string()}.
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
%%%===================================================================
|
||||
|
@ -26,15 +40,20 @@ compare(VsnA, VsnB) ->
|
|||
%%%===================================================================
|
||||
%%% Internal Functions
|
||||
%%%===================================================================
|
||||
-spec tokens(semvar()) -> parsed_semvar().
|
||||
tokens(Vsn) ->
|
||||
[MajorVsn, MinorVsn, RawPatch] = string:tokens(Vsn, "."),
|
||||
{PatchVsn, PatchString} = split_patch(RawPatch),
|
||||
{MajorVsn, MinorVsn, PatchVsn, PatchString}.
|
||||
|
||||
-spec split_patch(string()) ->
|
||||
{PatchVsn::string(), PatchStr::string()}.
|
||||
split_patch(RawPatch) ->
|
||||
{PatchVsn, PatchStr} = split_patch(RawPatch, {"", ""}),
|
||||
{lists:reverse(PatchVsn), PatchStr}.
|
||||
|
||||
-spec split_patch(string(), {AccPatchVsn::string(), AccPatchStr::string()}) ->
|
||||
{PatchVsn::string(), PatchStr::string()}.
|
||||
split_patch([], Acc) ->
|
||||
Acc;
|
||||
split_patch([Dig|T], {PatchVsn, PatchStr}) when Dig >= $0 andalso Dig =< $9 ->
|
||||
|
@ -42,10 +61,12 @@ split_patch([Dig|T], {PatchVsn, PatchStr}) when Dig >= $0 andalso Dig =< $9 ->
|
|||
split_patch(PatchStr, {PatchVsn, ""}) ->
|
||||
{PatchVsn, PatchStr}.
|
||||
|
||||
-spec compare_toks(parsed_semvar(), parsed_semvar()) -> boolean().
|
||||
compare_toks({MajA, MinA, PVA, PSA}, {MajB, MinB, PVB, PSB}) ->
|
||||
compare_toks2({to_int(MajA), to_int(MinA), to_int(PVA), PSA},
|
||||
{to_int(MajB), to_int(MinB), to_int(PVB), PSB}).
|
||||
|
||||
-spec compare_toks2(parsed_semvar(), parsed_semvar()) -> boolean().
|
||||
compare_toks2({MajA, _MinA, _PVA, _PSA}, {MajB, _MinB, _PVB, _PSB}) when MajA > MajB ->
|
||||
true;
|
||||
compare_toks2({_Maj, MinA, _PVA, _PSA}, {_Maj, MinB, _PVB, _PSB}) when MinA > MinB ->
|
||||
|
@ -60,7 +81,8 @@ compare_toks2({_Maj, _Min, _PV, PSA}, {_Maj, _Min, _PV, PSB}) when PSA > PSB ->
|
|||
true;
|
||||
compare_toks2(_ToksA, _ToksB) ->
|
||||
false.
|
||||
|
||||
|
||||
-spec to_int(string()) -> integer().
|
||||
to_int(String) ->
|
||||
case catch list_to_integer(String) of
|
||||
Integer when is_integer(Integer) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue