From d38c68a02d61abe0dfaf45a85747524a2d61c5ca Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 12 Dec 2018 18:04:54 +0100 Subject: Separates ID logic from the ID manager. --- src/ataxia_id.erl | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/ataxia_id.erl (limited to 'src/ataxia_id.erl') diff --git a/src/ataxia_id.erl b/src/ataxia_id.erl new file mode 100644 index 0000000..c809b90 --- /dev/null +++ b/src/ataxia_id.erl @@ -0,0 +1,63 @@ +-module(ataxia_id). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type type() :: binary(). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%% Actual Interface +-export +( + [ + null/0, + next/1 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec next_char (integer()) -> integer(). +next_char ($9) -> $a; +next_char ($z) -> $A; +next_char ($Z) -> $0; +next_char (C) -> (C + 1). + +-spec next_id_internal + ( + list(integer()), + boolean(), + list(integer()) + ) + -> list(integer()). +next_id_internal ([], true, Result) -> [$0|Result]; +next_id_internal ([], false, Result) -> Result; +next_id_internal ([$Z|Next], true, Result) -> + next_id_internal(Next, true, [$0|Result]); +next_id_internal ([Char|Next], true, Result) -> + next_id_internal(Next, false, [next_char(Char)|Result]); +next_id_internal ([Char|Next], false, Result) -> + next_id_internal(Next, false, [Char|Result]). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec next (type()) -> type(). +next (ID) -> + list_to_binary + ( + next_id_internal + ( + lists:reverse(binary:bin_to_list(ID)), + true, + [] + ) + ). + +-spec null () -> type(). +null () -> <<"">>. -- cgit v1.2.3-70-g09d2