view m-toolbox/classes/+utils/@helper/ver2num.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line source

% VER2NUM converts a version string into a number.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    ver2num
%
% DESCRIPTION: VER2NUM converts a version string into a number.
%
% CALL:        ver_num = ver2num(ver_str);
%
% INPUTS:      ver_str = major[.minor[.revision]] -> 1 or 1.2 or 1.2.3
%
% OUTPUT:      ver_num = major * 1 + minor * 0.01 + revision * 0.0001
%
% EXAMPLES:    '1'       --> 1
%              '1.2'     --> 1.02
%              '1.2.3'   --> 1.0203
%              '1.12.13' --> 1.1213
%
% VERSION:     $Id: ver2num.m,v 1.2 2009/01/25 16:00:40 mauro Exp $
%
% HISTORY:     07-07-2008 Diepholz
%                 Creation
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function ver_num = ver2num(ver_str)

ver_num = getVerParts(ver_str) * [1; .01; .0001];

function parts = getVerParts(ver_str)

parts = sscanf(ver_str, '%d.%d.%d')';
if length(parts) < 3
  parts(3) = 0; % zero-fills to 3 elements
end