|
20 | 20 | return |
21 | 21 | end |
22 | 22 |
|
23 | | -in = split(in, ' '); |
24 | | -in = split(in(1), '.'); |
| 23 | +inp = split(in, ' '); |
| 24 | +in_str = split(inp(1), "."); |
25 | 25 |
|
26 | | -ref = split(ref, '.'); |
| 26 | +refp = split(ref, ' '); |
| 27 | +ref_str = split(refp(1), "."); |
27 | 28 |
|
28 | | -for i = 1:min(length(in), length(ref)) |
29 | | - if in(i) > ref(i) |
| 29 | +% Compare numeric parts first |
| 30 | +for i = 1:min(length(in_str), length(ref_str)) |
| 31 | + in_num = double(in_str(i)); |
| 32 | + ref_num = double(ref_str(i)); |
| 33 | + |
| 34 | + if isnan(in_num) || isnan(ref_num) |
| 35 | + % assume values are leading integer with trailing string |
| 36 | + % extract integer part and compare |
| 37 | + in_num = double(regexp(in_str(i), "\d+", "match", "once")); |
| 38 | + ref_num = double(regexp(ref_str(i), "\d+", "match", "once")); |
| 39 | + |
| 40 | + if isnan(in_num) || isnan(ref_num) || in_num == ref_num |
| 41 | + % compare string parts |
| 42 | + in_str_part = regexp(in_str(i), "\D+", "match", "once"); |
| 43 | + ref_str_part = regexp(ref_str(i), "\D+", "match", "once"); |
| 44 | + if in_str_part > ref_str_part |
| 45 | + r = true; |
| 46 | + return |
| 47 | + elseif in_str_part < ref_str_part |
| 48 | + r = false; |
| 49 | + return |
| 50 | + end |
| 51 | + |
| 52 | + continue |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + % Compare numerically |
| 57 | + if in_num > ref_num |
30 | 58 | r = true; |
31 | 59 | return |
32 | | - elseif in(i) < ref(i) |
| 60 | + elseif in_num < ref_num |
33 | 61 | r = false; |
34 | 62 | return |
35 | 63 | end |
36 | 64 | end |
37 | 65 |
|
38 | | -r = in(end) >= ref(end); |
| 66 | +% If all compared parts are equal, compare lengths |
| 67 | +r = length(in_str) >= length(ref_str); |
39 | 68 |
|
40 | 69 | end |
41 | 70 |
|
42 | 71 | %!assert(version_atleast("1.2.3", "1.2")) |
| 72 | +%!assert(version_atleast("20.11a", "20.3b")) |
0 commit comments