Commit 46b1f3b9 authored by Michael Siegel's avatar Michael Siegel 👔
Browse files

Implement `Dec_To_Base36`

parent f06db771
......@@ -3,7 +3,7 @@
--
-- a ____ to facilitate random note-taking -- rewrite…
--
-- Version 0.28.4
-- Version 0.28.5
--
--
-- Copyright 2021 Michael Siegel
......@@ -28,13 +28,14 @@ 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;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
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.4";
Program_Version : constant String := "0.28.5";
Base_Dir : constant String := Env_Vars.Value("HOME") & "/.mote_R";
Data_Dir : constant String := Base_Dir & "/notes";
......@@ -63,6 +64,29 @@ procedure Mote is
return Result;
end Base36_To_Dec;
function Dec_To_Base36 (Decimal_Number : Natural) return String is
Base36_Base : constant := 36;
Base36_Digits : constant String := "0123456789abcdefghijklmnopqrstuvwxyz";
Dividend : Natural := Decimal_Number;
Quotient : Natural;
Remainder : Natural;
Result : Unbounded_String;
begin
loop
Quotient := Dividend / Base36_Base;
Remainder := Dividend rem Base36_Base;
Result := Base36_Digits(Remainder + 1) & Result;
exit when Quotient = 0;
Dividend := Quotient;
end loop;
while Length(Result) < 4 loop
Result := "0" & Result;
end loop;
return To_String(Result);
end Dec_To_Base36;
procedure Show_Help is
-- Display help text
-- Provide per-command help text, depending on what sub-command was run,
......@@ -100,5 +124,3 @@ 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