Fix range-based reference formatter.

Fixes: lp:1792483
* https://bugs.launchpad.net/kicad/+bug/1792483

(cherry picked from commit 243b05b2c3)
This commit is contained in:
Jeff Young 2018-09-14 12:58:50 +01:00
parent 5d8c3e5033
commit e8c8bf8d11
1 changed files with 11 additions and 12 deletions

View File

@ -829,33 +829,32 @@ wxString SCH_REFERENCE_LIST::Shorthand( std::vector<SCH_REFERENCE> aList )
while( i < aList.size() )
{
wxString ref = aList[ i ].GetRef();
int numRef = aList[ i ].m_NumRef;
size_t j = i;
size_t range = 1;
while( j + 1 < aList.size() && aList[ j + 1 ].GetRef() == ref )
j = j + 1;
while( i + range < aList.size()
&& aList[ i + range ].GetRef() == ref
&& aList[ i + range ].m_NumRef == numRef + range )
{
range++;
}
if( !retVal.IsEmpty() )
retVal << wxT( ", " );
if( j == i )
if( range == 1 )
{
retVal << ref << aList[ i ].GetRefNumber();
}
else if( j == i + 1 )
{
retVal << ref << aList[ i ].GetRefNumber();
retVal << wxT( ", " );
retVal << ref << aList[ j ].GetRefNumber();
}
else
{
retVal << ref << aList[ i ].GetRefNumber();
retVal << wxT( " - " );
retVal << ref << aList[ j ].GetRefNumber();
retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
}
i = j + 1;
i+= range;
}
return retVal;