From f369cc23a9d3664dabecf280e2d1d0b980d19ad4 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 6 Oct 2022 15:03:58 -0700 Subject: [PATCH] Handle arbitrary unit counts --- eeschema/lib_symbol.cpp | 16 +-- qa/unittests/eeschema/test_lib_part.cpp | 145 ++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 8 deletions(-) diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 93686e340a..07a1a84786 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -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; diff --git a/qa/unittests/eeschema/test_lib_part.cpp b/qa/unittests/eeschema/test_lib_part.cpp index c82008af99..7819946fbd 100644 --- a/qa/unittests/eeschema/test_lib_part.cpp +++ b/qa/unittests/eeschema/test_lib_part.cpp @@ -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,