@@ -841,71 +841,36 @@ fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
841841 // This particular form is documented in the GNU coding standards:
842842 // https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
843843
844- // don't start parsing in the middle of a number
845- let mut prev_was_digit = false ;
846- let mut in_parens = false ;
847- for ( pos, c) in full_version_line. char_indices ( ) {
848- if in_parens {
849- if c == ')' {
850- in_parens = false ;
851- }
852- continue ;
853- } else if c == '(' {
854- in_parens = true ;
855- continue ;
856- }
857-
858- if prev_was_digit || !c. is_digit ( 10 ) {
859- prev_was_digit = c. is_digit ( 10 ) ;
860- continue ;
844+ let mut splits = full_version_line. rsplit ( ' ' ) ;
845+ let version_string = splits. next ( ) . unwrap ( ) ;
846+
847+ let mut splits = version_string. split ( '.' ) ;
848+ let major = splits. next ( ) . unwrap ( ) ;
849+ let minor = splits. next ( ) . unwrap ( ) ;
850+ let patch = splits. next ( ) ;
851+
852+ let major: u32 = major. parse ( ) . unwrap ( ) ;
853+ let ( minor, patch) : ( u32 , u32 ) = match minor. find ( |c : char | !c. is_digit ( 10 ) ) {
854+ None => {
855+ let minor = minor. parse ( ) . unwrap ( ) ;
856+ let patch: u32 = match patch {
857+ Some ( patch) => match patch. find ( |c : char | !c. is_digit ( 10 ) ) {
858+ None => patch. parse ( ) . unwrap ( ) ,
859+ Some ( idx) if idx > 3 => 0 ,
860+ Some ( idx) => patch[ ..idx] . parse ( ) . unwrap ( ) ,
861+ } ,
862+ None => 0 ,
863+ } ;
864+ ( minor, patch)
861865 }
862-
863- prev_was_digit = true ;
864-
865- let line = & full_version_line[ pos..] ;
866-
867- let next_split = match line. find ( |c : char | !c. is_digit ( 10 ) ) {
868- Some ( idx) => idx,
869- None => continue , // no minor version
870- } ;
871-
872- if line. as_bytes ( ) [ next_split] != b'.' {
873- continue ; // no minor version
866+ // There is no patch version after minor-date (e.g. "4-2012").
867+ Some ( idx) => {
868+ let minor = minor[ ..idx] . parse ( ) . unwrap ( ) ;
869+ ( minor, 0 )
874870 }
871+ } ;
875872
876- let major = & line[ ..next_split] ;
877- let line = & line[ next_split + 1 ..] ;
878-
879- let ( minor, patch) = match line. find ( |c : char | !c. is_digit ( 10 ) ) {
880- Some ( idx) => {
881- if line. as_bytes ( ) [ idx] == b'.' {
882- let patch = & line[ idx + 1 ..] ;
883-
884- let patch_len =
885- patch. find ( |c : char | !c. is_digit ( 10 ) ) . unwrap_or_else ( || patch. len ( ) ) ;
886- let patch = & patch[ ..patch_len] ;
887- let patch = if patch_len > 3 || patch_len == 0 { None } else { Some ( patch) } ;
888-
889- ( & line[ ..idx] , patch)
890- } else {
891- ( & line[ ..idx] , None )
892- }
893- }
894- None => ( line, None ) ,
895- } ;
896-
897- if minor. is_empty ( ) {
898- continue ;
899- }
900-
901- let major: u32 = major. parse ( ) . unwrap ( ) ;
902- let minor: u32 = minor. parse ( ) . unwrap ( ) ;
903- let patch: u32 = patch. unwrap_or ( "0" ) . parse ( ) . unwrap ( ) ;
904-
905- return Some ( ( ( major * 1000 ) + minor) * 1000 + patch) ;
906- }
907-
908- None
873+ Some ( ( ( major * 1000 ) + minor) * 1000 + patch)
909874}
910875
911876/// Returns (LLDB version, LLDB is rust-enabled)
0 commit comments