summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ataxia_id.erl')
-rw-r--r--src/ataxia_id.erl63
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 () -> <<"">>.