/* * Created by PyramIDE. * User: フランスのトトロ aka (David RENÉ) * Date: 09/07/2017 * Time: 00:39 * © David RENÉ */ 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, //major Word8 b, //minor Word8 c, //release Word8 d //user defined )= 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 final_value = value | ((v&0xFF)<< (current * 8)), if current = 0 then success(version(final_value)) else convert_digits_to_Version(t, current -1, final_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 .