Skip to content
Snippets Groups Projects
Commit adbad78d authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Add int_to_str(int, w) variant for fixed widths.

parent 8f5173f7
No related branches found
No related tags found
1 merge request!389Resolve L2SDP-1013
This commit is part of merge request !389. Comments created here will be created in the context of that merge request.
......@@ -53,6 +53,7 @@ package common_str_pkg is
function hex_nibble_to_slv(c: character) return std_logic_vector;
function int_to_str(int: integer) return string;
function int_to_str(int, w: integer) return string;
function real_to_str(re: real; width : integer; digits : integer) return string;
procedure print_str(str : string);
......@@ -222,10 +223,9 @@ package body common_str_pkg is
when 'X' => v_result := "XXXX";
when 'z' => v_result := "ZZZZ";
when 'Z' => v_result := "ZZZZ";
when others => v_result := "0000";
end case;
return v_result;
when others => v_result := "0000";
end case;
return v_result;
end hex_nibble_to_slv;
function int_to_str(int: integer) return string is
......@@ -238,6 +238,19 @@ package body common_str_pkg is
return v_str;
end;
function int_to_str(int, w: integer) return string is
constant c_len: natural := nof_digits_int(int);
variable v_line: LINE;
variable v_str: string(1 to c_len) := (others => ' ');
variable v_ret: string(1 to w) := (others => ' ');
begin
STD.TEXTIO.WRITE(v_line, int);
v_str(v_line.ALL'range) := v_line.all;
deallocate(v_line);
v_ret(w - c_len + 1 to w) := v_str; -- right align v_str in v_ret
return v_ret;
end;
function real_to_str(re: real; width : integer; digits : integer) return string is
-- . The number length is width + 1, with +1 for the . in the floating point number.
-- However if width is too small to fit the number, then it will use more characters.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment