with Ada.Strings.Fixed; package body Images is use Ada.Strings.Fixed; use Ada.Text_IO; function Adjust (Image : String; Width : Field; Negative : Boolean; Zero_Filled : Boolean) return String is -- Apply Width, Negative, & Zero_Filled to Image Blank : constant Character := ' '; Zero : constant Character := '0'; Minus : constant Character := '-'; begin -- Adjust if Zero_Filled then if Negative then return Minus & (1 .. Width - Image'Length - 1 => Zero) & Image; else return (1 .. Width - Image'Length => Zero) & Image; end if; else if Negative then return (1 .. Width - Image'Length - 1 => Blank) & Minus & Image; else return (1 .. Width - Image'Length => Blank) & Image; end if; end if; end Adjust; function Signed_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String is package Number_IO is new Integer_IO (Number); use Number_IO; Image : String (1 .. 100); Start : Positive; Stop : Positive; Negative : constant Boolean := Value < 0; begin -- Signed_Image Put (To => Image, Item => Value, Base => Base); case Base is when 10 => Start := Index_Non_Blank (Image); Stop := Image'Last; if Negative then Start := Start + 1; end if; when 2 .. 9 | 11 .. 16 => Start := 1 + Index (Image, "#"); Stop := Image'Last - 1; when others => raise Program_Error; end case; return Adjust (Image (Start .. Stop), Width, Negative, Zero_Filled); end Signed_Image; function Modular_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String is package Number_IO is new Modular_IO (Number); use Number_IO; Image : String (1 .. 100); Start : Positive; Stop : Positive; begin -- Modular_Image Put (To => Image, Item => Value, Base => Base); case Base is when 10 => Start := Index_Non_Blank (Image); Stop := Image'Last; when 2 .. 9 | 11 .. 16 => Start := 1 + Index (Image, "#"); Stop := Image'Last - 1; when others => raise Program_Error; end case; return Adjust (Image (Start .. Stop), Width, False, Zero_Filled); end Modular_Image; end Images;