# # # bytes utilities # # subroutine(get_bytes_unit(string bytes_value), ( # returns the bytes unit of a bytes value # i.e. "15MB" or "15M" returns "MB"; "800" returns "bytes" bool match_unit = matches_regular_expression(bytes_value, "([a-zA-Z]*)$"); string matched_value = $1; string unit_value = "bytes"; if (matched_value ne "") then ( string s = lowercase(substr(matched_value, 0, 1)); if (s eq "k") then ( unit_value = "KB"; ) else if (s eq "m") then ( unit_value = "MB"; ) else if (s eq "g") then ( unit_value = "GB"; ) else if (s eq "t") then ( unit_value = "TB"; ) else ( unit_value = "bytes"; ); ); # debug_message("\n#### bytes_value: " . bytes_value . "\n"); # debug_message("#### match in \$1 variable: " . matched_value . "\n"); # debug_message("#### unit_value: " . unit_value . "\n\n"); unit_value; )); subroutine(get_bytes_number(string bytes_value), ( # returns the bytes number of a bytes value # i.e. "15MB" returns "15" bool match_number = matches_regular_expression(bytes_value, "([0-9]*)"); $1; ));