adacl-strings-hex.ads

1--------------------------------------------------------------- {{{1 ----------
2--: Copyright © 2003 … 2023 Martin Krischik «krischik@users.sourceforge.net»
3------------------------------------------------------------------------------
4--: This library is free software; you can redistribute it and/or modify it
5--: under the terms of the GNU Library General Public License as published by
6--: the Free Software Foundation; either version 2 of the License, or (at your
7--: option) any later version.
8--:
9--: This library is distributed in the hope that it will be useful, but
10--: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11--: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12--: License for more details.
13--:
14--: You should have received a copy of the GNU Library General Public License
15--: along with this library; if not, write to the Free Software Foundation,
16--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17--------------------------------------------------------------- }}}1 ----------
18
19pragma License (Modified_Gpl);
20pragma Ada_2022;
21
22with Interfaces;
23
24---
25-- @summary
26-- Strings with hex numbers.
27--
28-- @description
29-- Operation on hex string which don't contain the 16# and #
30--
31package AdaCL.Strings.Hex is
32
33 --
34 -- Given an modulus type returns an hex character string without the base marker.
35 --
36 --: @generic Unsigned_Type Modulo type to convert to a hex string.
37 --: @generic Width Width of the hex string formated to. String is filled with leading 0
38 --: @param Value Value to convert to hex
39 --: @return Fixed width character string repesenting the value
40 generic
41 type Unsigned_Type is mod <>;
42 Width : Integer := Unsigned_Type'Size / 4;
43 function Generic_Image (Value : in Unsigned_Type) return String with
44 Post => (Generic_Image'Result'Length = Width);
45
46 --
47 -- Given an modulus type returns an hex character string without the base marker.
48 --
49 --: @generic Unsigned_Type Modulo type to convert to a hex string.
50 --: @generic Width Width of the hex string formated to. String is filled with leading 0
51 --: @param Value Value to convert to hex
52 --: @return Fixed width character string repesenting the value
53 generic
54 type Unsigned_Type is mod <>;
55 Width : Integer := Unsigned_Type'Size / 4;
56 function Generic_Wide_Image (Value : in Unsigned_Type) return Wide_String with
57 Pure_Function, Post => (Generic_Wide_Image'Result'Length = Width);
58
59 ---
60 -- Given a string to hex digits return the value as an unsigned type
61 --
62 --: @generic Unsigned_Type Modulo type to convert to a hex string.
63 --: @param Image Image to convert to number
64 --: @return Fixed width character string repesenting the value
65 generic
66 type Unsigned_Type is mod <>;
67 function Generic_Value (Image : in String) return Unsigned_Type;
68
69 ---
70 -- Given a string to hex digits return the value as an unsigned type
71 --
72 --: @generic Unsigned_Type Modulo type to convert to a hex string.
73 --: @param Image Image to convert to number
74 --: @return Fixed width character string repesenting the value
75 generic
76 type Unsigned_Type is mod <>;
77 function Generic_Wide_Value (Image : in Wide_String) return Unsigned_Type with
78 Pure_Function, Inline;
79
80 ----------------------------------------------------------------------------
81
82 ---
83 -- Given an Unsigned_8 returns an hex 2 character hex string without the base marker
84 --
85 --: @param Value Value to convert to hex
86 --: @return Fixed 2 character string repesenting the value
87 function Image (Value : in Interfaces.Unsigned_8) return String with
88 Post => (Image'Result'Length = 2);
89
90 ---
91 -- Given an Unsigned_16 returns an hex 4 character hex string without the base marker
92 --
93 --: @param Value Value to convert to hex
94 --: @return Fixed 4 character string repesenting the value
95 function Image (Value : in Interfaces.Unsigned_16) return String with
96 Post => (Image'Result'Length = 4);
97
98 ---
99 -- Given an Unsigned_32 returns an hex 8 character hex string without the base marker
100 --
101 --: @param Value Value to convert to hex
102 --: @return Fixed 8 character string repesenting the value
103 function Image (Value : in Interfaces.Unsigned_32) return String with
104 Post => (Image'Result'Length = 8);
105
106 ---
107 -- Given an Unsigned_64 returns an hex 16 character hex string without the base marker
108 --
109 --: @param Value Value to convert to hex
110 --: @return Fixed 16 character string repesenting the value
111 function Image (Value : in Interfaces.Unsigned_64) return String with
112 Pure_Function, Inline, Post => (Image'Result'Length = 16);
113
114 ----------------------------------------------------------------------------
115
116 ---
117 -- Given hex string, return its Value as a Unsigned_8.
118 --
119 --: @param Image Hex String without 16#...#.
120 --: @return parsed Unsigned_8 value
121 function Value (Image : in String) return Interfaces.Unsigned_8;
122
123 ---
124 -- Given hex string, return its Value as a Unsigned_64.
125 --
126 --: @param Image Hex String without 16#...#.
127 --: @return parsed Unsigned_16 value
128 function Value (Image : in String) return Interfaces.Unsigned_16;
129
130 ---
131 -- Given hex string, return its Value as a Unsigned_64.
132 --
133 --: @param Image Hex String without 32#...#.
134 --: @return parsed Unsigned_32 value
135 function Value (Image : in String) return Interfaces.Unsigned_32;
136
137 ---
138 -- Given hex string, return its Value as a Unsigned_64.
139 --
140 --: @param Image Hex String without 16#...#.
141 --: @return parsed Unsigned_64 value
142 function Value (Image : in String) return Interfaces.Unsigned_64 with
143 Pure_Function, Inline;
144
145end AdaCL.Strings.Hex;
146
147---------------------------------------------------------------- {{{ ----------
148--: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
149--: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr :
150--: vim: set spell spelllang=en_gb