Commit f06db771 authored by Michael Siegel's avatar Michael Siegel 👔
Browse files

Implement `Base36_To_Dec`

We're going to use base-36 IDs.
parent a10b31c5
......@@ -3,7 +3,7 @@
--
-- a ____ to facilitate random note-taking -- rewrite…
--
-- Version 0.28.3
-- Version 0.28.4
--
--
-- Copyright 2021 Michael Siegel
......@@ -25,14 +25,16 @@ with Ada.Command_Line; use Ada.Command_Line;
with Ada.Containers.Indefinite_Vectors;
with Ada.Directories; use Ada.Directories;
with Ada.Environment_Variables;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Mote is
package Env_Vars renames Ada.Environment_Variables;
Program_Name : constant String := "mote";
Invocation_Name : constant String := Simple_Name(Command_Name);
Program_Version : constant String := "0.28.3";
Program_Version : constant String := "0.28.4";
Base_Dir : constant String := Env_Vars.Value("HOME") & "/.mote_R";
Data_Dir : constant String := Base_Dir & "/notes";
......@@ -41,6 +43,26 @@ procedure Mote is
-- Conf_File : constant String := Conf_Dir & "/mote.conf";
Next_ID_File : constant String := Base_Dir & "/next_id";
function Base36_To_Dec (Base36_String : String) return Natural is
Base36_Base : constant := 36;
Base36_Digits : constant String := "0123456789abcdefghijklmnopqrstuvwxyz";
Decimal_Value : Integer;
Exponent : Natural := 0;
Result : Natural := 0;
Invalid_Input : exception;
begin
for I in reverse Base36_String'Range loop
Decimal_Value := Index(Base36_Digits, Base36_String(I .. I)) - 1;
if Decimal_Value < 0 then
raise Invalid_Input;
end if;
Result := Result + Decimal_Value * Base36_Base ** Exponent;
Exponent := Exponent + 1;
end loop;
return Result;
end Base36_To_Dec;
procedure Show_Help is
-- Display help text
-- Provide per-command help text, depending on what sub-command was run,
......@@ -78,3 +100,5 @@ procedure Mote is
begin
null;
end Mote;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment