File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -27,15 +27,13 @@ impl Version {
27
27
}
28
28
29
29
pub fn parse ( s : & str ) -> Option < Self > {
30
- let s = s. lines ( ) . next ( ) ?. trim ( ) ;
31
- let s = s. rfind ( '_' ) . map ( |i| & s[ ..i] ) . unwrap_or ( s) ;
32
- let mut parts = s. split ( '.' ) ;
33
- let v = Self :: new (
34
- parts. next ( ) ?. parse ( ) . ok ( ) ?,
35
- parts. next ( ) ?. parse ( ) . ok ( ) ?,
36
- parts. next ( ) ?. parse ( ) . ok ( ) ?,
37
- ) ;
38
- parts. next ( ) . map_or ( Some ( v) , |_| None )
30
+ let re = Regex :: new ( r"^(1)\.(8|10)\.(\d\d?)(_\d+)?(-patch\d+)?$" ) . ok ( ) ?;
31
+ let captures = re. captures ( s) . ok ( ) ?;
32
+ Some ( Self {
33
+ major : c. get ( 1 ) . and_then ( |c| c. as_str ( ) . parse :: < u8 > ( ) . ok ( ) ) ?,
34
+ minor : c. get ( 2 ) . and_then ( |c| c. as_str ( ) . parse :: < u8 > ( ) . ok ( ) ) ?,
35
+ micro : c. get ( 3 ) . and_then ( |c| c. as_str ( ) . parse :: < u8 > ( ) . ok ( ) ) ?,
36
+ } )
39
37
}
40
38
41
39
pub fn is_valid ( & self ) -> bool {
You can’t perform that action at this time.
0 commit comments