diff --git a/eeschema/sch_validators.cpp b/eeschema/sch_validators.cpp index 56f8fa88d1..aba7d013f4 100644 --- a/eeschema/sch_validators.cpp +++ b/eeschema/sch_validators.cpp @@ -202,14 +202,29 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow* aParent ) } +wxRegEx SCH_NETNAME_VALIDATOR::m_busGroupRegex( R"([^$]?{)", wxRE_ADVANCED ); + + wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const { - if( NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) ) + // 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 angle + // brackets are also used for variable expansion + + if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) && + !NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) ) + { + return _( "Signal name contains '{' and '}' but is not a valid group bus name" ); + } return NETNAME_VALIDATOR::IsValid( str ); } diff --git a/eeschema/sch_validators.h b/eeschema/sch_validators.h index d7d7ad5b6a..a858a3ff6d 100644 --- a/eeschema/sch_validators.h +++ b/eeschema/sch_validators.h @@ -90,9 +90,14 @@ public: NETNAME_VALIDATOR( aValidator ) { } + virtual wxObject* Clone() const override { return new SCH_NETNAME_VALIDATOR( *this ); } + protected: /// @return the error message if the contents of \a aVal are invalid. wxString IsValid( const wxString& aVal ) const override; + +private: + static wxRegEx m_busGroupRegex; }; #endif // _SCH_VALIDATORS_H_