
Update to message on strings of variable length using a function which expands to 25 char
-- This is a more rubust function than the one I just passed. It checks
for
-- strings longer than 25. It can be used to clamp a string to 25
characters.
-- Thus an element can be defined of type String25_Typ, and a value can be
assigned as shown -- below:
-- variable SomeVAr : String25_Typ;
-- SomeVar := T25("Hello"); -- expanded to 25 charactes.
-- This is not a truly variable length (i.e. it is constrained), but the
user need not concern
-- himself with counting the number of necessary spaces to make up a total
of 25.
-- In addition, the access type "line" is not used.
package T25_Pkg is
subtype String25_Typ is string(1 to 25);
function T25(StringIn_c : string) return String25_Typ;
end T25_Pkg;
package body T25_Pkg is
function T25(StringIn_c : string) return String25_Typ is
variable Char25_v : String25_Typ := (others => ' ');
begin
if StringIn_c'length > 25 then
return StringIn_c(String25_Typ'range);
assert false
report "String is linger than 25"
severity warning;
end if;
LP_Lbl : for Index_i in 1 to StringIn_c'length loop
Char25_v(Index_i) := StringIn_c(Index_i);
end loop LP_Lbl;
return Char25_v;
end T25;
end T25_Pkg;
Ben Cohen is the author of an upcoming book "VHDL Coding Styles and
Methodologies" to be published by Kluwer Academics Publishers.