diff --git a/CHANGELOG.md b/CHANGELOG.md index dafb1c35add485c97ae993d363ce79768b023c51..f96fdc8a2888594cf0a094cb086a3d21e6bec809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- VHDL functions to convert characters and strings to upper/lower case. ## [1.0.0] - 2019-10-21 ### Added diff --git a/modules/common/gencores_pkg.vhd b/modules/common/gencores_pkg.vhd index 4b0f986d0c3f72d862a8ede5b66c6309d56d52c8..454c8e642130a7233211c32273a215b5e8151ba8 100644 --- a/modules/common/gencores_pkg.vhd +++ b/modules/common/gencores_pkg.vhd @@ -726,6 +726,12 @@ package gencores_pkg is function f_pick (cond : std_logic; if_1 : std_logic_vector; if_0 : std_logic_vector) return std_logic_vector; + -- Functions to convert characters and strings to upper/lower case + function to_upper(c : character) return character; + function to_lower(c : character) return character; + function to_upper(s : string) return string; + function to_lower(s : string) return string; + end package; package body gencores_pkg is @@ -954,4 +960,46 @@ package body gencores_pkg is return f_pick (f_to_std_logic(cond), if_1, if_0); end function f_pick; + ------------------------------------------------------------------------------ + -- Functions to convert characters and strings to upper/lower case + ------------------------------------------------------------------------------ + + function to_upper(c : character) return character is + variable i : integer; + begin + i := character'pos(c); + if (i > 96 and i < 123) then + i := i - 32; + end if; + return character'val(i); + end function to_upper; + + function to_lower(c : character) return character is + variable i : integer; + begin + i := character'pos(c); + if (i > 64 and i < 91) then + i := i + 32; + end if; + return character'val(i); + end function to_lower; + + function to_upper(s : string) return string is + variable uppercase : string (s'range); + begin + for i in s'range loop + uppercase(i) := to_upper(s(i)); + end loop; + return uppercase; + end to_upper; + + function to_lower(s : string) return string is + variable lowercase : string (s'range); + begin + for i in s'range loop + lowercase(i) := to_lower(s(i)); + end loop; + return lowercase; + end to_lower; + end gencores_pkg;