| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-12-12 18:04:54 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-12-12 18:04:54 +0100 | 
| commit | d38c68a02d61abe0dfaf45a85747524a2d61c5ca (patch) | |
| tree | 1493290911bd494ec4fd76f1d0e2bbb7917285a5 /src/ataxia_id.erl | |
| parent | 6b2fd0aae5067469598fa404f9163ab2ac87f69e (diff) | |
Separates ID logic from the ID manager.
Diffstat (limited to 'src/ataxia_id.erl')
| -rw-r--r-- | src/ataxia_id.erl | 63 | 
1 files changed, 63 insertions, 0 deletions
| 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 () -> <<"">>. | 


