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 | |
19 | pragma License (Modified_Gpl); |
20 | pragma Ada_2022; |
21 | |
22 | with 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 | -- |
31 | package AdaCL.Wide_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. Wide_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 Wide_String with |
44 | Pure_Function, Post => (Generic_Image'Result'Length = Width); |
45 | |
46 | --- |
47 | -- Given a string to hex digits return the value as an unsigned type |
48 | -- |
49 | --: @generic Unsigned_Type Modulo type to convert to a hex string. |
50 | --: @generic Value Value to convert to hex |
51 | --: @return Fixed width character string repesenting the value |
52 | generic |
53 | type Unsigned_Type is mod <>; |
54 | function Generic_Value (Image : in Wide_String) return Unsigned_Type with |
55 | Pure_Function; |
56 | |
57 | ---------------------------------------------------------------------------- |
58 | |
59 | --- |
60 | -- Given an Unsigned_8 returns an hex 2 character hex string without the base marker |
61 | -- |
62 | --: @param Value Value to convert to hex |
63 | --: @return Fixed 2 character string repesenting the value |
64 | function Image (Value : in Interfaces.Unsigned_8) return Wide_String with |
65 | Pure_Function, Inline, Post => (Image'Result'Length = 2); |
66 | |
67 | --- |
68 | -- Given an Unsigned_16 returns an hex 4 character hex string without the base marker |
69 | -- |
70 | --: @param Value Value to convert to hex |
71 | --: @return Fixed 4 character string repesenting the value |
72 | function Image (Value : in Interfaces.Unsigned_16) return Wide_String with |
73 | Pure_Function, Inline, Post => (Image'Result'Length = 4); |
74 | |
75 | --- |
76 | -- Given an Unsigned_32 returns an hex 8 character hex string without the base marker |
77 | -- |
78 | --: @param Value Value to convert to hex |
79 | --: @return Fixed 8 character string repesenting the value |
80 | function Image (Value : in Interfaces.Unsigned_32) return Wide_String with |
81 | Pure_Function, Inline, Post => (Image'Result'Length = 8); |
82 | |
83 | --- |
84 | -- Given an Unsigned_64 returns an hex 16 character hex string without the base marker |
85 | -- |
86 | --: @param Value Value to convert to hex |
87 | --: @return Fixed 16 character string repesenting the value |
88 | function Image (Value : in Interfaces.Unsigned_64) return Wide_String with |
89 | Pure_Function, Inline, Post => (Image'Result'Length = 16); |
90 | |
91 | ---------------------------------------------------------------------------- |
92 | |
93 | --- |
94 | -- Given hex string, return its Value as a Unsigned_8. |
95 | -- |
96 | --: @param Image Hex Wide_String without 16#...#. |
97 | --: @return parsed Unsigned_8 value |
98 | function Value (Image : in Wide_String) return Interfaces.Unsigned_8 with |
99 | Pure_Function, Inline; |
100 | |
101 | --- |
102 | -- Given hex string, return its Value as a Unsigned_64. |
103 | -- |
104 | --: @param Image Hex Wide_String without 16#...#. |
105 | --: @return parsed Unsigned_16 value |
106 | function Value (Image : in Wide_String) return Interfaces.Unsigned_16 with |
107 | Pure_Function, Inline; |
108 | |
109 | --- |
110 | -- Given hex string, return its Value as a Unsigned_64. |
111 | -- |
112 | --: @param Image Hex Wide_String without 32#...#. |
113 | --: @return parsed Unsigned_32 value |
114 | function Value (Image : in Wide_String) return Interfaces.Unsigned_32 with |
115 | Pure_Function, Inline; |
116 | |
117 | --- |
118 | -- Given hex string, return its Value as a Unsigned_64. |
119 | -- |
120 | --: @param Image Hex Wide_String without 16#...#. |
121 | --: @return parsed Unsigned_64 value |
122 | function Value (Image : in Wide_String) return Interfaces.Unsigned_64 with |
123 | Pure_Function, Inline; |
124 | |
125 | end AdaCL.Wide_Strings.Hex; |
126 | |
127 | ---------------------------------------------------------------- {{{ ---------- |
128 | --: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab : |
129 | --: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr : |
130 | --: vim: set spell spelllang=en_gb |