Handle arbitrary unit counts

This commit is contained in:
Seth Hillbrand 2022-10-06 15:03:58 -07:00
parent 098e96f1c7
commit f369cc23a9
2 changed files with 153 additions and 8 deletions

View File

@ -589,6 +589,9 @@ wxString LIB_SYMBOL::SubReference( int aUnit, bool aAddSeparator )
{
wxString subRef;
if( aUnit < 1 )
return subRef;
if( m_subpartIdSeparator != 0 && aAddSeparator )
subRef << wxChar( m_subpartIdSeparator );
@ -602,17 +605,14 @@ wxString LIB_SYMBOL::SubReference( int aUnit, bool aAddSeparator )
// use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
// first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
int u;
aUnit -= 1; // Unit number starts to 1. now to 0.
while( aUnit >= 26 ) // more than one letter are needed
do
{
u = aUnit / 26;
subRef << wxChar( m_subpartFirstId + u -1 );
aUnit %= 26;
}
u = ( aUnit - 1 ) % 26;
subRef = wxChar( m_subpartFirstId + u ) + subRef;
aUnit = ( aUnit - u ) / 26;
} while( aUnit > 0 );
u = m_subpartFirstId + aUnit;
subRef << wxChar( u );
}
return subRef;

View File

@ -197,6 +197,151 @@ BOOST_AUTO_TEST_CASE( SubReference )
false,
"AA",
},
{
28,
false,
"AB",
},
{
53,
false,
"BA",
},
{
79,
false,
"CA",
},
{
105,
false,
"DA",
},
{
131,
false,
"EA",
},
{
157,
false,
"FA",
},
{
183,
false,
"GA",
},
{
209,
false,
"HA",
},
{
235,
false,
"IA",
},
{
261,
false,
"JA",
},
{
287,
false,
"KA",
},
{
313,
false,
"LA",
},
{
339,
false,
"MA",
},
{
365,
false,
"NA",
},
{
391,
false,
"OA",
},
{
417,
false,
"PA",
},
{
443,
false,
"QA",
},
{
469,
false,
"RA",
},
{
495,
false,
"SA",
},
{
521,
false,
"TA",
},
{
547,
false,
"UA",
},
{
573,
false,
"VA",
},
{
599,
false,
"WA",
},
{
625,
false,
"XA",
},
{
651,
false,
"YA",
},
{
677,
false,
"ZA",
},
{
702,
false,
"ZZ",
},
{
703,
false,
"AAA",
},
{
728,
false,
"AAZ",
},
{ // haven't configured a separator, so should be nothing
1,
true,