version.anubis
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 09/07/2017
* Time: 00:39
* © Calexium
*/
transmit tools/basis.anubis
transmit system/string.anubis
public type Version:
version(
Word32 numeric,
)
.
public define Maybe(Version) to_Version(String version_string).
public define Version
version(
Word8 a,
Word8 b,
Word8 c,
Word8 d
)=
version( word32(word16(d, c), word16(b, a)))
.
public define Version
version
(
String version_str
)=
if to_Version(version_str) is
{
failure then version(0),
success(_version) then _version
}
.
define Maybe(Version)
convert_digits_to_Version
(
List(String) digits,
Int current,
Word32 value
)=
if digits is
{
[] then success(version(value)),
[h . t] then
if length(h) = 0 then
convert_digits_to_Version(t, current -1, value)
else
if decimal_scan(h) is
{
failure then failure,
success(v) then
if v > 255 then //the value is greater than Word8 capacity
failure
else
with value = value | ((v&0xFF)<< (current * 8)),
if current = 0 then
success(version(value))
else
convert_digits_to_Version(t, current -1, value)
}
}.
/** convert a version string into Word32 value
* The version string, is made up of 4 values separated by period.
* At this time, these values musn't be higher than 255 because, each value are
* concatenated into Word32. Then each word8 is a part of final value the most significant
* value will be placed into most significant place into Word32
* for example
* String Word32 Representation
* 2.5 [ 2 | 5 | 0 | 0 ]
* 1.34.2.165 [ 1 | 43 | 2 | 165 ]
*
*/
public define Maybe(Version)
to_Version
(
String ver_string
)=
with list_digits = split_by_token(ver_string, '.'),
if length(list_digits) > 4 then
failure
else
convert_digits_to_Version(list_digits, 3, 0).
public define String
to_String
(
Version _version
) =
since _version is version(numeric),
(numeric >> 24) + "." +
((numeric >> 16) & 0xFF) + "." +
((numeric >> 8) & 0xFF) + "." +
(numeric & 0xFF)
.
public define String
String s + Version v =
s + to_String(v)
.
public define String
Version v + String s =
to_String(v) + s
.