Fix value checking for gerbview autodetect

X/Y/T require a numeric value after the starting letter.  The previous
check only looked for numbers but values can validly start with other
character (e.g. '-').  This puts the value checking into the C-local
double conversion that should find all variants

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15633
This commit is contained in:
Seth Hillbrand 2023-09-12 12:44:14 -07:00
parent 2d54bc42cb
commit e1966a1259
1 changed files with 26 additions and 4 deletions

View File

@ -80,6 +80,7 @@
#include <gerbview_settings.h>
#include <cmath>
#include <charconv>
#include <dialogs/html_message_box.h>
@ -407,22 +408,43 @@ bool EXCELLON_IMAGE::TestFileIsExcellon( const wxString& aFullFileName )
foundT = false; /* Found first T after X or Y */
else
{
// verify next char is digit
if( isdigit( letter[1] ) )
double x_val;
char* start = letter + 1;
char* end = letter + strlen( letter );
std::from_chars_result res = std::from_chars( start, end, x_val );
if( res.ec != std::errc::invalid_argument )
foundT = true;
}
}
// look for X<number> or Y<number>
if( ( letter = strstr( line, "X" ) ) != nullptr )
if( isdigit( letter[1] ) )
{
double x_val;
char* start = letter + 1;
char* end = letter + strlen( letter );
std::from_chars_result res = std::from_chars( start, end, x_val );
if( res.ec != std::errc::invalid_argument )
foundX = true;
}
if( ( letter = strstr( line, "Y" ) ) != nullptr )
if( isdigit( letter[1] ) )
{
double x_val;
char* start = letter + 1;
char* end = letter + strlen( letter );
std::from_chars_result res = std::from_chars( start, end, x_val );
if( res.ec != std::errc::invalid_argument )
foundY = true;
}
}
}
catch( IO_ERROR& )
{
return false;