Fix bus validation.

Bus groups must be checked first as they can contain vectors inside
them.
This commit is contained in:
Jeff Young 2021-09-17 20:45:01 +01:00
parent 86ffb9a4bb
commit d32ca5b287
1 changed files with 15 additions and 11 deletions

View File

@ -208,24 +208,28 @@ wxRegEx SCH_NETNAME_VALIDATOR::m_busGroupRegex( R"((^|[^$_\^~]){)", wxRE_ADVANCE
wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const
{
wxString msg = NETNAME_VALIDATOR::IsValid( str );
if( !msg.IsEmpty() )
return msg;
// We don't do single-character validation here
if( str.Length() == 1 )
return wxString();
if( ( str.Contains( '[' ) || str.Contains( ']' ) ) &&
!NET_SETTINGS::ParseBusVector( str, nullptr, nullptr ) )
{
return _( "Signal name contains '[' or ']' but is not a valid vector bus name." );
}
// Figuring out if the user "meant" to make a bus group is somewhat trickier because curly
// Figuring out if the user "meant" to make a bus group is somewhat tricky because curly
// braces are also used for formatting and variable expansion
if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) &&
!NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) )
if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) )
{
return _( "Signal name contains '{' and '}' but is not a valid group bus name" );
if( !NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) )
return _( "Signal name contains '{' and '}' but is not a valid bus name" );
}
else if( str.Contains( '[' ) || str.Contains( ']' ) )
{
if( !NET_SETTINGS::ParseBusVector( str, nullptr, nullptr ) )
return _( "Signal name contains '[' or ']' but is not a valid bus name." );
}
return NETNAME_VALIDATOR::IsValid( str );
return wxString();
}